Data validation is an important part of a JSF application (which has existed since JSF 1.2), because it allows us to separate the business logic from the tedious checks that help us to obtain only valid information from the user. Data is validated in the Process Validations phase (if the immediate
attribute is set to true
, this processing will occur at the end of the Apply Request Values phase instead) and should be valid and ready to be used before the Update Model Values phase.
Besides the built-in validators, we can write our own customized validators. A public class that implements the Validator
interface and overrides the validate
method is recognized by JSF as a validator. There are two ways to configure a validator in JSF: using the @FacesValidator
annotation or the <validator>
tag in faces-config.xml
.
Suppose that we have the following e-mail validator configured using @FacesValidator
:
@FacesValidator(value = "emailValidator")
public...