In addition to providing standard validators for our use, JSF allows us to create custom validator
s. This can be done in one of two ways—by creating a custom validator
class or by adding validation
methods to our named beans.
In addition to the standard validators, JSF allows us to create custom validators by creating a Java class implementing the javax.faces.validator.Validator
interface.
The following class implements an email validator, which we will use to validate the email text input field in our customer data entry screen:
package net.ensode.glassfishbook.jsfcustomval;
import javax.faces.application.FacesMessage;
import javax.faces.component.UIComponent;
import javax.faces.component.html.HtmlInputText;
import javax.faces.context.FacesContext;
import javax.faces.validator.FacesValidator;
import javax.faces.validator.Validator;
import javax.faces.validator.ValidatorException;
import org.apache.commons.lang3.StringUtils;
@FacesValidator...