Wednesday, August 15, 2012

Solution to Control Global Editable/Readonly Mode in ADF BC

There is requirement, when we need to disable/enable editable data access globally per user session for entire application. When implementing this requirement, you should keep in mind ADF BC passivation/activation - data should stay in correct state even between activation/passivation iterations. Global control for editable mode in ADF BC can based on - Solution for Sharing Global User Data in ADF BC. Sample application in this post, is based on that article. Described solution for global editable/readonly mode is generic across all Task Flows, EO's and AM's, there is no dependency to specific Task Flow, EO or AM.

Download sample application - Sample architecture is described here:

Editable/Readonly access is set from session scope, user can trigger it by certain action. We should not access session scope directly in ADF BC, its why we override Data Control class - CustomADFBCDataControl (read more here) and pass session scope value into ADF BC User Data. CustomADFBCDataControl class contains overriden executeIteratorBindingIfNeeded() method responsible to prepare iterator binding, this method is called each time when data collection is accessed, it allows to pass correct editable or readonly flag and store it in User Data. Custom User Data is passivated/activated with ADF BC lifecycle, same data is accessed from generic EO implementation class isAttributeUpdateable(int) method.

Solution is tested with disabled AM pooling, to proof it works under stress load:

isAttributeUpdateable(int) method checks User Data variable custom_ReadOnlyMode and decided to render editable or readonly data:

executeIteratorBindingIfNeeded() method updates User Data variable custom_ReadOnlyMode, each time when data is accessed - this allows to force editable or readonly rendering mode on any EO:

By default form is rendered in editable mode, in my sample:

User changes sessions scope variable to readonly, ADF BC custom User Data is updated - page refresh happens and EO isAttributeUpdateable(int) method marks all attributes to be readonly:

This change happens globally, across all Task Flows, AM's and EO's. Locations tab renderes read-only data from Locations Task Flow:

Switch back to editable - data is rendered editable again:

In the log you can see that, two AM were initialized - Locations and Departments. Data access (readonly/editable) variable was passed each time when data was accessed from iterator:

This allows to mark EO attributes in generic EO class for editable/readonly access.

Sample application implements different Task Flow for each tab, this means editable/readonly access is independent of Task Flow and control directly in ADF BC level through custom User Data variable initialized from Data Control class on data access generically:


Xahar Hassan said...

Hi Andrejus,

Good article. My requirement is almost same but slightly different. Rather than user switching from Read only to Editable mode, I need that to be Administered. Through means of ADF Security, I need to restrict certain users to have read only access while others can edit the same page.

Don Kleppinger said...

Here a link to the solution we used which use a new role and a custom base App module class. I've linked back to your blog at the end.

Andrej Baranovskij said...

Thanks ;)


Muddasar Amin said...

It is really helpful to me, thank you for sharing but Your application doesn't exist anymore :) please provide some refreshed link.


Andrej Baranovskij said...

I have updated download URL - try now.