Announcement

Collapse
No announcement yet.
X
  • Filter
  • Time
Clear All
new posts

    Date comparison in velocity validator

    Hello,

    I am trying to use a velocity expression to make sure that a certain date falls after the current date. I have gone trough the documentation that I could find (http://www.smartclient.com/smartgwte...tySupport.html and http://www.smartclient.com/smartgwte...erverCondition) but found nothing that could help me in the area of type conversion (string to date) or date comparison (compare two dates and determine the current date in some way).

    I tried the following ($value yields a string value):
    Code:
    $value<=$date.calendar
    (was not working - syntax error - I expect because the $date utility is not known in the velocity scope)

    and also desperatly:
    Code:
    $value.date.compareTo('2011-08-12 00:00:00')<=0
    (Lexical error)

    I would greatly appreciate any reference to a sample or piece of documentation to get this working.

    for your reference, the full validator XML looks like this:
    Code:
    <validator stopIfFalse="false" stopOnError="false" type="serverCustom" validateOnChange="true">
    <serverCondition><![CDATA[$value.compareTo('2011-08-12 00:00:00')<=0']]></serverCondition>
    <errorMessage>An unexpected error occured: The incident date must be a future date.</errorMessage>
    </validator>

    We are on the latest 2.5 build.


    thanks a lot in advance.
    Last edited by hin3x; 12 Aug 2011, 06:11.

    #2
    $value will be a date if the field is declared as type "date". As with Java, call getTime() on each Date and compare that.

    Comment


      #3
      I see, sadly our date values are represented as String internally. I created a custom validator to cover this, thanks for the feedback!

      Comment

      Working...
      X