Monday, November 10, 2014

Using ADF BC Declarative Built-in Rules (Part 7 of 10): Range validator

The "Range Validator" is another entity attribute validator which can be be defined at either the entity or attribute level but pertains to an entity attribute just like the "Compare", "Key Exists", "Length" and "List" validators.

As it's name suggests you can use the "Range" validator to ensure that an attribute value falls either within or outside some specified minimum and maximum values. For example, ensure that an employee's salary is between $10,000 and $20,000.

For the purpose of demoing the "Range" validator I have created an 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 default view object based on the Employees entity object and a default application module.

Next let’s define a "Range" validator on the Employees entity object to ensure that an employee's salary is within a specified minimum and maximum values. So on the  “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 “Range”, select the attribute that you want to define the validator, in my demo it's the "Salary" attribute and then select an operator, either Between or NotBetween. In my demo I have selected the "Between" operator.

Under the range section define a minimum and a maximum 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 new salary value using the newValue keyword.


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

Run the Application module to test your "Range" validator and try to update an employee's salary to a value greater than 20,000. The "Range" validator should have fired displaying your error message.

Download sample application: Range Validator