Creating a Custom Validator
If you need a validator that is not available from among those provided in the Palette view and are familiar with writing Java code, you can create your own validator. 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, you should create your own library and load it through the project.
To create a custom validator
1. In the design canvas, select the input control for which you need to create a custom validator.
2. In the General tab of the Properties view, type a unique ID in the ID field and click away from the view.
3. In the design canvas, right-click the control and then click Event Handlers > Validate Handler.
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!"));
}
4. After the TODO comments, place the Java code needed to perform the needed validation.