Java Reference
In-Depth Information
Using a Custom Validator on page 132 explains how to use the custom validator tag on
the page.
Using a Custom Validator
To register a custom validator on a component, you must do one of the following:
• Nest the validator's custom tag inside the tag of the component whose value you
want to be validated.
• Nest the standard f:validator tag within the tag of the component and refer-
ence the custom Validator implementation from the f:validator tag.
Here is a hypothetical custom formatValidator tag for the Credit Card Number field,
nested within the h:inputText tag:
Click here to view code image
<h:inputText id="ccno" size="19"
...
required="true">
<mystore:formatValidator
formatPatterns="9999999999999999|9999 9999 9999
9999|9999-9999-9999-9999" />
</h:inputText>
<h:message styleClass="validationMessage" for="ccno"/>
This tag validates the input of the ccno field against the patterns defined by the page au-
thor in the formatPatterns attribute.
You can use the same custom validator for any similar component by simply nesting the
custom validator tag within the component tag.
If the application developer who created the custom validator prefers to configure the at-
tributes in the Validator implementation rather than allow the page author to configure
the attributes from the page, the developer will not create a custom tag for use with the
validator.
In this case, the page author must nest the f:validator tag inside the tag of the com-
ponent whose data needs to be validated. Then the page author needs to do one of the
following:
• Set the f:validator tag's validatorId attribute to the ID of the validator
that is defined in the application configuration resource file.
Search WWH ::




Custom Search