Uploaded image for project: 'Wicket'
  1. Wicket
  2. WICKET-2540

Date Validation - message formatting of the date

    XMLWordPrintableJSON

Details

    • Improvement
    • Status: Resolved
    • Minor
    • Resolution: Fixed
    • None
    • 1.4.4, 1.5-M1
    • wicket
    • None

    Description

      Have the ability to pass a date format string to the validator so that the dates will format how the developer desires when a validation error is hit. I have included an example of how I worked around the problem. Feel free to use this as a starting point.

      Example:

      public class CustomMinimumDateValidator extends AbstractValidator<Date> {

      private final Date minimum;
      private final String format;

      public CustomMinimumDateValidator(Date minimum, String format)

      { this.minimum = minimum; this.format = format; }

      @Override
      protected void onValidate(IValidatable<Date> validatable) {
      Date value = validatable.getValue();
      if (value.before(minimum))

      { error(validatable); }

      }

      @Override
      protected Map<String, Object> variablesMap(IValidatable<Date> validatable)

      { final Map<String, Object> map = super.variablesMap(validatable); SimpleDateFormat sdf = new SimpleDateFormat(format); String minimumString = sdf.format(minimum); map.put("mindate", minimumString); map.put("inputdate", sdf.format(validatable.getValue())); return map; }

      @Override
      protected String resourceKey()

      { return "CustomMinimumDateValidator.minimum"; }

      }

      Attachments

        Activity

          People

            jdonnerstag Juegen Donnerstag
            jschneller Jeff Schneller
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:

              Time Tracking

                Estimated:
                Original Estimate - 4h
                4h
                Remaining:
                Remaining Estimate - 4h
                4h
                Logged:
                Time Spent - Not Specified
                Not Specified