0% found this document useful (0 votes)
118 views

How To Create A Custom JSF Validator

How to Create a Custom JSF Validator 1. Create a Java class that implements the javax.faces.validator.Validator 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 javax.faces.FormatValidator interface, which has accessor methods for setting the formatPatterns attribute. This attribute specifies the acceptabl

Uploaded by

jaae251
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
118 views

How To Create A Custom JSF Validator

How to Create a Custom JSF Validator 1. Create a Java class that implements the javax.faces.validator.Validator 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 javax.faces.FormatValidator interface, which has accessor methods for setting the formatPatterns attribute. This attribute specifies the acceptabl

Uploaded by

jaae251
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 3

How to Create a Custom JSF Validator

1. Create a Java class that implements the javax.faces.validator.Validator 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 javax.faces.FormatValidator 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
javax.faces.validator.ValidatorException to throw the appropriate exceptions and

javax.faces.application.FacesMessage to generate the corresponding error messages.

Page 2 of 3
3. Register the validator in the faces-config.xml file.
ƒ Open the faces-config.xml file and select the Overview tab in the editor window.
The faces-config.xml 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 validator’s ID (as configured in faces-config.xml 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 validator’s 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

You might also like