17.8. Implementing a validator

We want to restrict the second number to odd values. Since there is no standard validator for this, you will need to write your own validator. In addition, you will also need to do the following:

  • Register your validator in the configuration file.

  • Link your validator to the number2 field so it can be checked.

Execute the following steps:

1.
Right-click the itso.jsf.calculator package
a. Select New → Class.
b. Enter OddValidator as name.
c. Click Add for Interfaces.
d. Locate the javax.faces.validator.Validator interface and click OK.
e. Select Inherited abstract methods. Click Finish.
Figure 17-37. New Java class
2.
The skeleton class is generated with this method skeleton:
public void validate(FacesContext ...

Get IBM Rational Application Developer V6 Portlet Application Development and Portal Tools now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.