Time for action – using the custom JSF validator on the client side
Let us see how we can create a custom JSF validator and use it with the PrimeFaces CSV framework, by performing the following steps:
- Create the
CreditCardValidator
class to validate whether the credit card number is in the 9999 9999 9999 9999 format or not:import java.util.*; import java.util.regex.Pattern; import javax.faces.application.FacesMessage; import javax.faces.component.UIComponent; import javax.faces.context.FacesContext; import javax.faces.validator.FacesValidator; import javax.faces.validator.Validator; import javax.faces.validator.ValidatorException; import org.primefaces.validate.ClientValidator; @FacesValidator("creditCardValidator") public class CreditCardValidator implements Validator, ClientValidator { private Pattern pattern; private static final String CC_PATTERN = "^\\d{4} \\d{4} \\d{4} \\d{4}$"; public CreditCardValidator() { pattern = Pattern.compile...