Hi
I've written a custom validator and error message and I'm adding my own variables to the error message by overriding variablesMap().
My error message looks like thie:
<properties>
<entry key="LocalDateTimeRangeValidator">${input} must be between ${startDate} and ${endDate}</entry>
</properties>

As I understand 3 default variables should be substituted by the validator for ${label} ${input} and ${name}; if I use ${label} and $ {name} they get substituted fine but ${input} is not:

WicketMessage: Exception 'java.lang.IllegalArgumentException: Value of variable [[input]] could not be resolved while interpolating [[$ {input} must be between ${startDate} and ${endDate}]]' occurred during validation com.resprompt.webapp.validation.LocalDateTimeValidator $LocalDateTimeRangeValidator on component 0:carHireSearchForm:dropoffDate

I've had a look through the source for the Wicket built-in validators and I can't seem any instance of 'input' being added explicitly to the variablesMap, any ideas why this isn't being set for me?


public abstract class LocalDateTimeValidator<T extends BaseLocal> extends AbstractValidator<T> {

    private static final long serialVersionUID = -5922211613447031430L;
private static Logger log = LoggerFactory.getLogger(LocalDateTimeValidator.class);

public static <U extends BaseLocal> LocalDateTimeValidator<U> range(U startDate, U endDate) {
        return new LocalDateTimeRangeValidator<U>(startDate, endDate);
    }

public static class LocalDateTimeRangeValidator<T extends BaseLocal> extends LocalDateTimeValidator<T> {

private static final long serialVersionUID = -6335920679560594249L;
        private T startDate;
        private T endDate;

        public LocalDateTimeRangeValidator(T startDate, T endDate) {
            this.startDate = startDate;
            this.endDate = endDate;
        }

        @Override
        protected void onValidate(IValidatable<T> validatable) {
            BaseLocal date = validatable.getValue();
            if (!(date.isAfter(startDate) && date.isBefore(endDate))) {
                error(validatable);
            }
        }

        @Override
        protected String resourceKey() {
            return "LocalDateTimeRangeValidator";
        }

        @Override
protected Map<String, Object> variablesMap(IValidatable<T> validatable) {
            Map<String, Object> map = super.variablesMap(validatable);
            map.put("startDate", startDate);
            map.put("endDate", endDate);
            return map;
        }
    }
}

Thanks
Gianni




---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to