protected void onValidate(IValidatable validatable) { Date value = (Date)validatable.getValue(); if (value.before(minimum) || value.after(maximum)) { error(validatable); } }
/** * Gets a <code>Date</code> range validator for checking if the <code>Date</code> value falls * between the minimum and maximum <code>Date</code> values. If that is not the case, an error * message will be generated with the key "DateValidator.range". The message keys that can be * used are: * <p> * <ul> * <li>${minimum}: the minimum date</li> * <li>${maximum}: the maximum date</li> * <li>${input}: the input the user gave</li> * <li>${name}: the name of the <code>Component</code> that failed</li> * <li>${label}: the label of the <code>Component</code> - either comes from * <code>FormComponent.labelModel</code> or resource key [form-id].[form-component-id] in that * order</li> * </ul> * * @param minimum * the minimum <code>Date</code> * @param maximum * the maximum <code>Date</code> * * @return the requested <code>DateValidator</code> */ public static DateValidator range(Date minimum, Date maximum) { return new RangeValidator(minimum, maximum, null); }
/** * Gets a <code>Date</code> range validator for checking if the <code>Date</code> value * falls between the minimum and maximum <code>Date</code> values. If that is not the case, an * error message will be generated with the key "DateValidator.range". The message keys that can * be used are: * <p> * <ul> * <li>${minimum}: the minimum date</li> * <li>${maximum}: the maximum date</li> * <li>${input}: the input the user gave</li> * <li>${name}: the name of the <code>Component</code> that failed</li> * <li>${label}: the label of the <code>Component</code> - either comes from * <code>FormComponent.labelModel</code> or resource key [form-id].[form-component-id] in that * order</li> * </ul> * * @param minimum * the minimum <code>Date</code> * @param maximum * the maximum <code>Date</code> * * @return the requested <code>DateValidator</code> */ public static DateValidator range(Date minimum, Date maximum) { return new RangeValidator(minimum, maximum); }
/** * @see #range(Date, Date) * * @param minimum * the minimum <code>Date</code> * @param maximum * the maximum <code>Date</code> * @param format * The format string used to format the date with SimpleDateFormat * * @return the requested <code>DateValidator</code> */ public static DateValidator range(Date minimum, Date maximum, String format) { return new RangeValidator(minimum, maximum, format); }
@Override protected void onValidate(IValidatable<Date> validatable) { Date value = validatable.getValue(); if (value.before(minimum) || value.after(maximum)) { error(validatable); } } }