List of usage examples for com.google.gwt.libideas.validation.client ErrorHandler reportError
public void reportError(Subject subject, String errorMessage)
From source file:com.google.gwt.demos.validation.client.ValidationDemo.java
License:Apache License
/** * This validator checks that the statute of limitations has not run out for * the given crime code. The Mayberry judicial system encodes the statute of * limitations as the first two digits of the crime code; this is checked * against the date of the crime.//from ww w . j a v a2s . c o m */ private Validator createStatuteValidator(final TextBox crimeCode) { // Now, to show a custom validator. Using BuiltInValidator because we want // to use the built-in error messages for Date conversion. Validator statuteValidator = new BuiltInValidator() { public void checkValid(Subject subject, ErrorHandler handler) { String code = crimeCode.getText(); Date dateOfCrime = null; try { dateOfCrime = getDate(subject); } catch (ValidationException e) { // Not our problem if the dateOfCrime cannot be formatted as a date. } if (dateOfCrime == null) { return; } if (code.matches(CRIME_CODE_FORMAT)) { int years = statuteOfLimitations(code.trim()); Date lastValidDate = offsetDate(years); if (dateOfCrime.before(lastValidDate)) { // We could get this information from a messages file in we needed // internationalization. handler.reportError(subject, "Statute of limitations has expired."); } } } }; return statuteValidator; }