Hi,
I'm trying to add a validator for the date field. I've created the
validator "infuture" to verify the picked date is in the future
<t:datefield t:id="endTime" value="item.endTime"
t:validate="required,infuture"/>
In my app module, i've added
/**
* Contributes the set of validators:
*/
public static void contributeFieldValidatorSource(
MappedConfiguration<String, Validator> configuration) {
configuration.add("infuture", new DateValidator());
}
And my DateValidator is
import java.util.Date;
import org.apache.tapestry5.Field;
import org.apache.tapestry5.MarkupWriter;
import org.apache.tapestry5.ValidationException;
import org.apache.tapestry5.ioc.MessageFormatter;
import org.apache.tapestry5.services.FormSupport;
import org.apache.tapestry5.validator.AbstractValidator;
public class DateValidator extends AbstractValidator<Void, Date> {
public DateValidator() {
super(null, Date.class, "date-must-be-in-future");
}
public void render(Field field, Void constraintValue,
MessageFormatter formatter, MarkupWriter writer,
FormSupport formSupport) {
// TODO Auto-generated method stub
}
public void validate(Field field, Void constraintValue,
MessageFormatter formatter, Date value) throws
ValidationException {
if (value.before(new Date())) {
throw new ValidationException(buildMessage(formatter, field));
}
}
private String buildMessage(MessageFormatter formatter, Field field) {
return formatter.format(field.getLabel());
}
}
It's a simple copy-paste adapt of other validator such as
org.apache.tapestry5.validator.Email
That works well.
My problem I can't set the default message in case of validation error.
I've always a [[missing key: date-must-be-in-future]], even if i put the
key in my WEB-INF/app.properties.
Looking a source code, it seams the source of the message are in
tapestry-code/org/apache/tapestry5/internal/ValidationMessages.properties.
I can only add my message on a per-page-per-field basis ? Any way to
configure another global source of message, to put mine ?
Thanks for help.
Nicolas.
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscr...@tapestry.apache.org
For additional commands, e-mail: users-h...@tapestry.apache.org