Sunday, February 6, 2011

ADF Region Communication - Data Exchange Through Shared Data Control Java Class

There are several ways to exchange data between ADF regions. Here are the most common ones:

1. ADF Task Flow parameters - preferable option, is simple to use, however sometimes is not enough for complex scenarios

2. Contextual Events - flexible and powerful approach, but can be too complicated. When application grows, is hard to maintain and understand dependency between different Contextual Events. In certain situations, its mandatory to use Contextual Events, for example dependent region refresh

3. Page Definition Access through Data Control - we can access separate ADF region page definition through Data Control directly. While this works, is not advisable because it creates direct dependencies between regions

Every ADF region maintains its own Page Flow scope, this means even if you have two ADF regions on the same page - each ADF region will have its own Page Flow scope and it will not be allowed to enter another region Page Flow scope. If we would be allowed to share Page Flow scope between different regions, it would be easy to pass data from one ADF region to another, however this is not allowed by design. I will describe possible alternative - to use custom Data Control to exchange data.

What we can do in order to simplify data exchange between ADF regions is to define our own Java class and declare it as ADF Data Control. Download sample application -

Java class contains dataObject variable and initializer method:

DataPackage Data Control is generated for our simple Java class:

DataPackage Data Control provides dataObject and initializer method:

Sample application implements two ADF regions - header and detail. Using our custom DataPackage Data Control will share data from header to the detail. Data Control needs to be populated with default value, this can be done using default Method Call activity inside header ADF task flow:

At that point of time, when header region will be initialized, our data control will be populated with JobId from the first record available in VO:

Row selection listener for the header table component is overridden as well to set update Data Control with newly selected value:

Consumer ADF region - detail, declares Attribute Value that points to dataObject from our custom Data Control. This means that DataPackage DataPackage Data Control generated based on our Java class will act as a bridge and will allow to exchange data from producer to consumer ADF regions without using Contextual Events. Its also good, because there are no direct dependencies between two ADF regions, data exchange is done through proxy DataPackage Data Control created based on our Java class:

Detail ADF region contains CreateWithParams operation, this operation is referencing Attribute Value from DataPackage:

When ADF regions are loaded and header region is initialized, immediately DataPackage Data Control is initialized as well (as you saw before through default Method Call):

Press Create button available inside detail region - JobId value selected from header region will be populated automatically:

Select another row from header region and press Create button again - JobId will display newly selected value from header region:


Vipin said...

Hi Andre,

Quite informative article, I proud to be a follower of such a blog with this kind of article. I have a question for this blog. In the binding for create a new row with values, job id is being populated from the dataset. But while checking the same example, I observed that we can not add or delete the parameter using the edit action bindings. So how to specify the parameter there. If I took the case of this example, I also want to set salary which is constant to all new addition as 5000. How to set it as the parameter while clicking the edit binding is coming non editable. Even I am not sure How you add job id to that list.


Vipin said...

Got from your newest blog, about the same.

Thanks a lot.

Praveen said...

Hey Andre,

Was wondering if you could look into this and provide your valuable input. And I come across same issue when the called task flow is used as a region on a jspx page. The jspx view page is defined on the _taskflow.xml.

Thanks in advance for your help.

Vipin said...

Hi Andre,

Question is not related to this post, but I am google search put me always to this post for my search :-).

In application module we usually have two configuration one ls Local and other shared let say my module name is EMPDataAM then name of these configuration will be EMPDataAMLocal and EMPDataAMShared. I am not sure on what basis these configurations come into picture. When ever I ran UI its the Local one always been used. Can you please tell me usages of Shared.


Andrejus Baranovskis said...


I'm planning a blog post about this. But generally speaking, Local config is used always. Shared comes into picture only with Shared AM's, but still is used only internally bu ADF BC. If you tune ADF BC, tune Local.


Author said...

Is it possible to pass parameters, i.e., set PageFlow scope in containing TF from a region embedded in it ?

Andrejus Baranovskis said...

You mean to return values from nested region to parent region?


Israel said...

Is posible to pass values from region to the parent jspx with Shared datacontrols? I know it is posible with events, but I need something like sahred datacontrols (or shared variables)

Nick said...

Hi Andrejus,

I fail to understand how the proxy DC minimizes dependencies when both regions share the HrModuleDataControl. Can you explain?

Andrejus Baranovskis said...

One HrModuleDataControl is just example, to simplify use case. In real life, you will have different AM's. Focus of this blog is rather to present proxy DC idea and assume ADF BC is implementation specific.

Thanks for question.