About Standard JSF Validators

Validation is the process whereby editable component data is validated against rules or conditions before the data is updated into the model layer. For example an input field might have a minimum and maximum length. If the component data cannot be validated or does not pass the validation rules, the model will not be updated.

The JavaServer Faces (JSF) implementation provides standard validators that handle checks for string lengths and numeric ranges. The JSF validators implement the javax.faces.validator.Validator interface.

Standard Validator Tags

The supplied set of validator classes and their tags are:

Tag Class Checks whether...
f:validateDoubleRange          
DoubleRangeValidator A component value is within a specified range. The value must be convertible to floating-point type or a floating-point.
f:validateLength          
LengthValidator The length of a component value is within a specified range. The value must be of type java.lang.String.
f:validateLongRange          
LongRangeValidator A component value is within a specified range. The value must be any numeric type or String that can be converted to a long.

You use a validator tag by nesting the tag within a component, and specifying the allowable values for the component data in the tag attributes. The values can be literal values or value-binding expressions that reference the properties of beans. When a component has an attached validator, the validate() method first checks for a submitted value if the required attribute of the component is set to true. Then the validator is called.

Validators can be registered on UIInput components only, or components that extend UIInput. You can register more than one validator on a component. JSF calls the validators in the order they are added to the component.

For information about using the supplied validator tags, see Registering a Standard Validator on a Component. For a list of the supported tag attributes, see Reference: Standard JSF Converter and Validator Tags.

If you need more complex validation rules and checks, you can create your own custom validator. See Working with Custom JSF Converters and Validators for information about creating and registering custom validators with your application.


About the Conversion and Validation Process in JSF
About Conversion and Validation Errors
About Required Values and the immediate Attribute
Working with Standard JSF Converters and Validators