The tag handler associated with a custom validator tag must extend the ValidatorELTag class. This class is the base class for all custom tag handlers that create Validator instances and register them on UI components. The FormatValidatorTag class registers the FormatValidator instance onto the component.
The FormatValidatorTag tag handler class does the following:
Sets the ID of the validator.
Provides a set of accessor methods for each attribute defined on the tag.
Implements the createValidator method of the ValidatorELTag class. This method creates an instance of the validator and sets the range of values accepted by the validator.
The formatPatterns attribute of the formatValidator tag supports literals and value expressions. Therefore, the accessor method for this attribute in the FormatValidatorTag class must accept and return an instance of ValueExpression:
protected ValueExpression formatPatterns = null; public void setFormatPatterns(ValueExpression fmtPatterns){ formatPatterns = fmtPatterns; }
Finally, the createValidator method creates an instance of FormatValidator, extracts the value from the formatPatterns attribute’s value expression and sets the formatPatterns property of FormatValidator to this value:
the formatPatterns property of FormatValidator to this value:
protected Validator createValidator() throws JspException { FacesContext facesContext = FacesContext.getCurrentInstance(); FormatValidator result = null; if(validatorID != null){ result = (FormatValidator) facesContext.getApplication() .createValidator(validatorID); } String patterns = null; if (formatPatterns != null) { if (!formatPatterns.isLiteralText()) { patterns = (String) formatPatterns.getValue(facesContext.getELContext()); } else { patterns = formatPatterns.getExpressionString(); }