How to Create a Custom JSF Validator
1. Create a Java class that implements the [Link] interface. The
implementation must contain a public no-args constructor, a set of accessor methods for
any attributes, and a validate method that overrides the validate method of the Validator
interface.
Alternatively, you can implement the [Link] interface, which has
accessor methods for setting the formatPatterns attribute. This attribute specifies the
acceptable patterns for the data entered into the input component. For example, if you
want to validate the pattern of a credit card number, you create a formatPatterns
attribute for the allowed patterns. The implementation must contain a constructor, a set
of accessor methods for anyattributes, and a validate method that overrides the validate
method on the Validator interface.
Page 1 of 3
2. Add the needed validation logic. This logic should use
[Link] to throw the appropriate exceptions and
[Link] to generate the corresponding error messages.
Page 2 of 3
3. Register the validator in the [Link] file.
Open the [Link] file and select the Overview tab in the editor window.
The [Link] file is located in the <View_Project>/WEB-INF directory.
In the window, select Validators and click New.
To use a custom validator without a custom tag
you must nest the validators ID (as configured in [Link] file) inside the
af:validator tag.
1. From the Structure window, right-click the input component for which you want
to add validation, and choose Insert inside <component> > ADF Faces Core >
Validator.
2. Select the validators ID from the dropdown list and click OK.
JDeveloper inserts code on the JSF page that makes the validator ID a property of
the validator tag.
Page 3 of 3