Java Reference
In-Depth Information
Of course, a negative age wouldn't make much sense, however, our application
validates that user input is a valid integer with essentially no effort on our part.
The email address input field of our page is bound to a property of type String in
our managed bean. As such, there is no built-in validation to make sure that the user
enters a valid email address. In cases like this, we need to write our own custom
JSF validators.
Custom JSF validators must implement the javax.faces.validator.Validator
interface. This interface contains a single method named validate() . This method
takes three parameters: an instance of javax.faces.context.FacesContext , an
instance of javax.faces.component.UIComponent containing the JSF component
we are validating, and an instance of java.lang.Object containing the user
entered value for the component. The following example illustrates a typical
custom validator.
package com.ensode.jsf.validators;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
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.Validator;
import javax.faces.validator.ValidatorException;
 
Search WWH ::




Custom Search