Java Reference
In-Depth Information
Finally,
the
method
passes
the
message
to
the
constructor
of
javax.faces.validator.ValidatorException .
When the error message is displayed, the format pattern will be substituted for the {0} in
the error message, which, in English, is as follows:
Input must match one of the following patterns: {0}
You may wish to save and restore state for your validator, although state saving is not
usually necessary. To do so, you will need to implement the StateHolder interface
in addition to the Validator interface. To implement StateHolder , you would
need to implement its four methods: saveState(FacesContext) , re-
storeState(FacesContext, Object) , isTransient , and setTransi-
ent(boolean) . See “ Saving and Restoring State ” on page 113 for more information.
Specifying a Custom Tag
If you implemented a Validator interface rather than implementing a managed bean
method that performs the validation, you need to do one of the following:
• Allow the page author to specify the Validator implementation to use with the
f:validator tag. In this case, the Validator implementation must define its
own properties. Using a Custom Validator on page 132 explains how to use the
f:validator tag.
• Specify a custom tag that provides attributes for configuring the properties of the
validator from the page.
To specify a custom tag, you need to add the tag to the tag library descriptor for the ap-
plication, bookstore.taglib.xml .
Click here to view code image
<tag>
<tag-name>formatValidator</tag-name>
<validator>
<validator-id>formatValidator</validator-id>
<validator-
class>dukesbookstore.validators.FormatValidator</validator-class>
</validator>
</tag>
The tag-name element defines the name of the tag as it must be used in a Facelets page.
The validator-id element identifies the custom validator. The validator-class
element wires the custom tag to its implementation class.
Search WWH ::




Custom Search