Wednesday, October 19, 2011

Entity Attribute Validation Rule (Business Rule) based on Master View Object Attribute Example ADF 11g

Hi,
Here is an example case of entity attribute validation rule.

Download Sample Application.

This example is using HR Schema of Oracle XE.
The following case uses Employees and Departments Entities and View Objects.
All Business components are created through JDeveloper 11g wizard.
The validation will check if the ManagerId attribute of the Employees Entity has the same value as the ManagerId of the Department.
We consider that there should not be the same Manager of a Department and an Employee.
Just to clarify that this is an example and maybe the logic does not seem very logical....
The point is to present the solution.
So, what do we have so far?
Two Entities (Employees and Departments) with their association (Master is the Departments entity)
Two View Objects( Employees and Departments) with their corresponding entities and the appropriate view Link.

Now, as we said earlier, we want to prevent the user from setting managerId value, for an Employee, which is the same as the managerId value for the corresponding Department.

In order to implement this case the declarative way, we are going to create an Entity Attribute Validation Rule  or in other words, Entity Attribute Business Rule.

We locate the Employees entity and the ManagerId attribute and press the green plus sign:


A new wizard window  will appear that will guide us to create the validation we want.
For this scenario, we want to compare the Employees Entity managerId with the Departments View Object  managerId. For that reason, we will select the value View Object Attribute  value of the Compare With  choice list. Further more we set the Operator  to  Not Equals.

Location of te ManagerId

Setting the  Not Equals



The final thing to do is to set an appropriate message that will notify the user that this value cannot be accepted.

This Rule Definition will be triggered  when the Employees managerId attribute is the same as the Departments View Object managerId attribute.



In order to test the example, we do not need to  create any jspx.. Since this is a BC validation, all we have to do is run the Application Module:

In the following example: Department has ManagerId of nbr: 200

 We double click on the Employees view and change the managerId to 200 and press tab. The result will be the following: (the message is just for fun.. .not an actuall logic message.. or is it? :) )


And that is it..
Dont you just feel  a little bit more Declarative now?

Download Sample Application.


Regards.

No comments:

Post a Comment

LinkWithin

Related Posts Plugin for WordPress, Blogger...