Uploaded image for project: 'XWork'
  1. XWork
  2. XW-500

Can't specify date format anymore for min and max values when using annotation @DateRangeFieldValidator

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Closed
    • Major
    • Resolution: Fixed
    • 2.0.1
    • 2.0.2, 2.1
    • Tiger, Validators
    • None
    • windows server 2003, tomcat 5.5.23, xwork2.0.1 with struts 2.0.6
    • Patch

    Description

      When I was using struts 2.0.1 with Xwork 2.0.b1, I was able to use any date format for the min and max values of annotation @DateRangeFieldValidator, which was quite nice as I could use an ISO format like 2006-31-01 that doesn't depend on the locale at all, and it made all these date validations portable and quite standard.

      For this, I just had to declare my own date converter in the xwork-conversion.properties that can parse ISO format and it was used by default by Xwork to convert the min and max String values of the annotation into Date values for the DateRangeFieldValidator implementation... I really liked that.

      But unfortunately, it looks like since Xwork 2.0.1, this behavior has changed and I have to use the locale format for all my annotations attributes representing dates: which means I have to change them all....

      I had a look at class AnnotationValidationConfigurationBuilder and it looks like now, this builder tries to convert the min and max values with a new method called parseDateString().

      I don't know where it was done before but I think min and max where kept as Strings and OGNL was converting them into Dates when needed, cf. ObjectFactory.buildValidator() , which was perfect...

      The problem is that this parseDateString() method returns null if it it can't do the conversion instead of keeping the String so that OGNL can do its job later.

      If you plan to keep this first attempt of conversion with this parseDateString() method, would it be also possible to keep the previous behavior by putting a string in the params instead of null when your conversion fails, so that we can apply our own conversion later?

      The previous behavior made the date validation very customizable, i don't really see the use of this parseDateString() method...

      here is my proposition, in class com.opensymphony.xwork2.validator.AnnotationValidationConfigurationBuilder.processDateRangeFieldValidatorAnnotation(),

      replace:

      if ( v.min() != null && v.min().length() > 0)

      { params.put("min", parseDateString(v.min())); }

      if ( v.max() != null && v.max().length() > 0)

      { params.put("max", parseDateString(v.max())); }

      by

      if ( v.min() != null && v.min().length() > 0)

      { final Date minDate = parseDateString(v.min()); params.put("min", minDate == null ? v.min() : minDate); }

      if ( v.max() != null && v.max().length() > 0)

      { final Date maxDate = parseDateString(v.max()); params.put("max", maxDate == null ? v.max() : maxDate); }

      Thanks.

      Seb.

      Attachments

        Activity

          People

            rainerh Rainer Hermanns
            seib Sebastien Poirier
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: