Skip to main content

JSF Tip #2 - The JSF Validator API

Posted by mriem on September 3, 2012 at 4:55 AM PDT

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!