Date Validation - message formatting of the date
------------------------------------------------

                 Key: WICKET-2540
                 URL: https://issues.apache.org/jira/browse/WICKET-2540
             Project: Wicket
          Issue Type: Improvement
          Components: wicket
            Reporter: Jeff Schneller
            Priority: Minor


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";
                }
        }


-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.

Reply via email to