JSF Tip #2 - The JSF Validator API

The definition of a Validator according to the Validator interface:

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

The Faces Context is passed in so the validator can introspect various aspects of the request and response.

The UI component is passed in because the actual value will be stored in that UI component after it has been validated. Note in a later blog entry we will address validation across multiple components.

The value that is passed in is the actual value that needs to be validated. Note that the type is specified as Object so any value can be validated.

The validate method throws the ValidatorException when the validation fails. So if you want the request life cycle to terminate early this method needs to throw the ValidatorException.

That's all for this blog entry, see you soon!

Posted September 3, 2012