You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@wicket.apache.org by "Juergen Donnerstag (JIRA)" <ji...@apache.org> on 2009/10/23 22:04:00 UTC

[jira] Resolved: (WICKET-2540) Date Validation - message formatting of the date

     [ https://issues.apache.org/jira/browse/WICKET-2540?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Juergen Donnerstag resolved WICKET-2540.
----------------------------------------

       Resolution: Fixed
    Fix Version/s: 1.5-M1
                   1.4.4
         Assignee: Juergen Donnerstag

fixed

> 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
>            Assignee: Juergen Donnerstag
>            Priority: Minor
>             Fix For: 1.4.4, 1.5-M1
>
>   Original Estimate: 4h
>  Remaining Estimate: 4h
>
> 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.