About this task
To create a custom validator, you need Java
coding experience.
Composite Application Framework provides some initial code to get you started. A custom
validator is valid only for the portlet in which it is created. If you plan to
use a particular validator in many portlets, create your own library and load
it through the project.
To create a custom
validator
Procedure
-
Open a CAF view in the design
canvas and select the input control for which you want to create a custom
validator.
-
In the Properties view, click the
General tab.
-
In the
ID field, type a unique ID for the
validator.
-
In the design canvas, right-click
the control, and then click
Lifecycle > Custom
Validator.
Composite Application Framework creates some Java code in the managed bean and opens a
Java editor to the location of the code. An example of validator code created
for an input control is shown here:
/**
* Validator for the control with id='inputID'
*/
public void inputID_validator(javax.faces.context.FacesContext
context, javax.faces.component.UIComponent component, java.lang.Object
value) {
// TODO: Check the value parameter here, and if not valid,
do something like this:
// throw new ValidatorException(new FacesMessage("Not a valid value!"));
}
-
After the TODO comments, type the
Java code required for the validator.