Wednesday, May 30, 2012

ADF 11g R2 Model Layer Validation Functionality

There is new functionality available in ADF 11g R2 - ADF Model layer validation. In the most of the cases, we define validation in ADF directly inside ADF BC, on Entity objects. Depending on the use case, not all fields rendered on UI can be based on ADF BC attributes. We can define validations inside Page Definition for any attribute, but specifically it can be useful for transient attributes defined directly in Model layer and displayed on UI. This allows to minimize Java code to control business logic validation for transient fields defined in UI. In this post I will describe how to implement UI fields to capture values for ExecuteWithParams operation and apply Model validation for these fields.

Sample application - ADFModelValidationApp.zip, is designed to demonstrate why ADF Model layer validation concept is useful. Example is based on the concept of transient variables defined in Page Definition, read more here - Page Definition Variables to Store Temporary Page Values.

There will be two validation rules defined in ADF Model for searchable Salary value:

1. Salary value must be positive for lower range
2. Salary should not exceed 30000 for upper range

I have implemented View Criteria to search based on Salary attribute in range.


As per previous blog mentioned above, in Page Definition there are two variables defined to keep values entered by the user for lower and upper ranges:


There is custom UI created to simulate Search form:


Search form is wrapped into ADF subform with DefaultCommand to handle Enter keyboard action when user wants to execute search - it will invoke Search button automatically for the user:


Subform is set with DefaultCommand property:


Small hint - if you want to render validation error inline for input field, you must define validator tag and point to the attribute validator:


Validator property should point to the attribute from Page Definition (in our case this attribute points to Page Definition variable):


Finally input field is mapped with the same attribute from Page Definition:


Now let's move to the main topic - ADF Model layer validation. We can define validation rule directly for attribute binding in Page Definition - select attribute, choose More from Property Inspector and invoke Edit Validation Rule:


I have already one rule defined, to check for Salary value to be positive:


There are other validation rule types available - Compare, Length, List, Range, Regular Expression and Required:


Here how it looks on UI. Type negative value into Salary search From field, it will trigger ADF Model layer validation rule and show inline error message:


Same is true for Salary search To field, which is compared against maximum 30000:


When validation is passed successfully, search action is executed:


No comments: