Monday, August 4, 2014

Using ADF BC Declarative Built-in Rules (Part 5 of 10): Length Validator

The “Length Validator” is another validator that can be defined at either the entity level or the attribute level but pertains to an entity object attribute to compare the number of characters or bytes in an attribute value against a specified length.

For the purpose of this demo I have created a new ADF Fusion Web Application and created the basic business components that I will be using in this demo, an entity object based on the Employees HR table, a view object based on the Employees entity object and a default application module.

Next let’s define a “Length” validator on the Employees entity object to ensure that an employee’s first name is less than 10 characters. So on “Business Rules” tab of the Employees entity object, click on the green plus icon “Create new validator”.  This will open the “Add Validation Rule” editor for defining the validation specifics.

In the “Type” combo select “Length” and select the attribute on which you want to define the length validator. In my demo I have selected “FirstName”. Select the operator (Equals, NotEquals, LessThan, GreaterThan, LessOrEqualTo, GreaterOrEqualTo, Between), the comparison type (either Character or Bytes) and set the length value.

In the "Failure Handling" tab define a failure message and click "OK". In my example I have used a message token expression to construct a dynamic error message, passing to the failure message the employee’s first name.

If you inspect the Employee’s entity source code you will see that JDeveloper added a LengthValidationBean tag to the XML entity definition file.

Before testing our validator please ensure that your application module has the Employees view selected under the “Data Model”.

To test your validator, run the Application module and try to update an employee’s first name, providing a name greater than 10 characters. You should get your custom dynamic error message displayed.

Download sample application: Length Validator

No comments:

Post a Comment