previous | index | next

Implementing Custom Validator Classes

Similar to the process for custom converter classes:
  1. Implement a validator by implementing the javax.faces.validator.Validator interface

  2. Register the validator in faces-config.xml.

The Validator interface has only one method:

     void validate(FacesContext context, UIComponent component, Object value)

Validation failure throws a ValidatorException:

     if (validation fails) {
         FacesMessage message = ...;
         message.setSeverity(FacesMessage.SEVERITY_ERROR);
         throw new ValidatorException(message);
     }

previous | index | next