Using Validation Attributes How to Add Validation

Validating and Converting Input 6-13 Figure 6–2 Server-Side Validation Error

6.5.3 What You May Need to Know About Multiple Validators

You can set zero or more validators on a UI component. You can set the required attribute and use validators on a component. However, if you set the required attribute to true and the value is null or a zero-length string, the component is invalidated and any other validators registered on the component are not called. This combination might be an issue if there is a valid case for the component to be empty. For example, if the page contains a Cancel button, the user should be able to click that button and navigate off the page without entering any data. To handle this case, you set the immediate attribute on the Cancel button’s component to true. This attribute allows the action to be executed during the Apply Request Values phase. Then the default JSF action listener calls FacesContext.renderResponse, thus bypassing the validation whenever the action is executed. For more information see Chapter 4, Using the JSF Lifecycle with ADF Faces.

6.6 Creating Custom JSF Validation

You can add your own validation logic to meet your specific business needs. If you want custom validation logic for a component on a single page, you can create a validation method on the page’s backing bean. If you want to create logic that will be reused by various pages within the application, or if you want the validation to be able to run on the client side, you should create a JSF validator class. You can then create an ADF Faces version, which will allow the validator to run on the client.

6.6.1 How to Create a Backing Bean Validation Method

When you want custom validation for a component on a single page, create a method that provides the required validation on a backing bean. To add a backing bean validation method: 1. Insert the component that will require validation into the JSF page.

2. In the visual editor, double-click the component to open the Bind Validator

Property dialog.

3. In the Bind Validator Property dialog, enter or select the managed bean that will

hold the validation method, or click New to create a new managed bean. Use the default method signature provided or select an existing method if the logic already exists. When you click OK in the dialog, JDeveloper adds a skeleton method to the code and opens the bean in the source editor.