Monday, August 22, 2011

ADF BC : Make Table , Form ReadOnly based on condition.

 

Let’s say you have requirement ,if one person login he can update the field and other person login he cannot update the field based on role of person.

Let us use standard HR schema.

Scenario 1: If HR Login he can see the salary of employee.

Scenario 2:- if Accountant login he can update the salary to give raise.

1. Create ADF BC EO/VO for Employee table.

2.Create a page jspx and drop it on adfc-config.xml

3.Go to datacontrol and drop EmployeeView to page.

4.Run the page and every field will be editable by default since we have not provided any logic yet.

Now let us generate EmployeeRowImpl.java file since we will be dealing with attribute and single row at a time.

When we generate ROWImpl file for employee view object , we will see each attribute has given index.

image

So when this VO is rendering we can perform some business logic on interested attribute of Salary and make it readonly and editable.

isAttributeUpdateable(int i)

Please override this method on RowImpl.java , you can refer to oracle documentation for further explanation.

I wrote the following code for test before making it to final version based on role for testing.

image

As you can notice I have just compared attribute and if it is salary then make it read only and rest editable.

Run App Tester.

Woow , when I run app tester I can see only Salary is read only for each row.

image

Now let me run simple page with just Employee Table displayed with all records and see if this logic is making all salary disabled.

Wooow , here we go and our salary is read only now.

image

Now our next step is to secure this page and create two role HRRole and ActRole.

Two user each belonging to one role.

Configure Security

After going to Application –> Configure security , I configured security in ADF app.

Create two enterprise role.

image

Create two app role

image

Assigned enterprise role to app role.

image

image

Create two user and assign proper app role.

hr – ActAppRole

act – HrAppRole

image

Real Logic

When HR login we should make salary field read-only and if act login we should make it updatable.

Go back to RowImpl and write following line of code to verify user in roles.

Run app module tester.

image

If user belong to Hr role then make salary as read only ,otherwise editable.

Give permission to page before running jspx.

image

Let us run jspx now and login at HR and ACT and we will see that Salary column is read only for HR and editable for Act user.

image

1 comment:

  1. Hi,

    How can we do it for the entire table ? Do we need to do it separately for each column ?

    Thanks

    ReplyDelete