Wednesday, April 8, 2015

Simple (Effective) Refresh Approach for ADF Regions

I often hear developer asking about how to refresh different regions on the same page, when specific event happens in one of the regions - to refresh dependent regions. Usually developers would like to use something more simple than Contextual Event approach. There is more simple approach, may be it doesn't work for all the possible use cases - but it does it job, when just refresh is needed. This approach is based on dummy parameter value, being used as dependent region input parameter, with refresh option set to be ifNeeded.

For the sample test case, I'm using ADF 12c application (SimpleReloadRegionApp.zip). This application contains two AM's, to simulate two Data Controls to be used in separate regions:


Fragment from the first region, generates refresh event, when Save button is pressed. For this purpose, I have registered Property Listener to update flag variable. This variable value is initialised from refreshToken method, available in RefreshHelperBean:


Bean method is very simple, it takes current timestamp value and returns it to String. This value always will be changed and this ensures dependent region refresh:


Make sure to set input parameter for the region TF you want to refresh, this should be simple parameter of type String:


TF must call Execute operation, this will force to reload VO rowset data, before loading the fragment:


In the main page, where region is consumed, change refresh condition to ifNeeded and set refreshFlag parameter to point to the variable initialized in the first region (by property listener):


There are two regions rendered on the UI. Once I change data in the top region (form component) and press Save, second region below is refresh automatically and it fetches latest available data from DB:

11 comments:

Unknown said...

Hi, thank you for this tutorial, it's great.

But didn't work for me, maybe because I don't understand the part where i have to define the "Execute" method and call it before the fragment in my task flow.

Could you be more precise in what compose this method etc please ?

thank you a lot,

Leslie

Andrej Baranovskij said...

Hi,

There is nothing special about Execute method, this is standard data reload method from ADF, I'm calling it to re-query data.

Regards,
Andrejus

Unknown said...

Hi,
Thanks. I love your posts, helps me a lot.
I do exactly the way as your approach, but I have a big problem. I need to refresh region which contains a dvt:timeline and everything's alright until I dynamically change scale of timeline(startTime and endTime). Then PPR do not work properly (for sure this is a bug at this component).

Is there any around to re-render page fragment inside region without using ppr, but full region views reload (something like full page refresh but just for a region)?

Regards,
Sebastian

Andrej Baranovskij said...

Hi,

Yes, I think you can trigger navigation inside region. So, you can define navigation outcome to the fragment itself and trigger this navigation from outside - region navigation.

Regards,
Andrejus

Unknown said...

Hi!

I have noticed another strange thing, probably a bug.
Task flow is included as a region, Refresh=ifNeeded, activation=conditional and active=#{bindings.param eq 'value'}.
Why in such a case my region refreshes (task flow executes) even when active is evaluated to false? Input params was changed but I don't want to refresh this region (only other based on the same taskflow when active is evaluating to true)
It seams that Refresh=ifNeeded take a precedence over active=false!? Why? I think that this is a bug.

How can I prevent from refreshing this region and from re-exectuting task flow when Refresh=ifNeeded and input param was changed? (This input param is just a session refresh flag triggering regions(task flows) in many other cases)
Is there any different option to achieve this?

JDev 11.1.1.7

Regards,
Sebastian

Andrej Baranovskij said...

This needs to be tested, I don't have quick answer.

Regards,
Andrejus

Unknown said...

Hi Andrejus,

Am I correct to assume that this method will only work when the taskflows are sharing Data Controls?

Regards

Andrej Baranovskij said...

No difference, it will work with isolated also. I'm using session scope variable.

Andrejus

Unknown said...

I'm trying to figure out how to refresh a page on navigation. This is how it is suppose to work:
1. Main page displays some records.
2. On button click, I navigate to a page where I can create new record.
3. Upon submitting it, I should come back to Main page and display all records including new one.

I've achieved navigation using navigation rules etc. But in step 3 it doesn't show the new record. It shows only when I manually refresh it. Do you have an idea how do I achieve this?

Anonymous said...

aravindpattar ,

I should come back to Main page and display all records including new one...While going back execute the query and refresh the form it will show the new record.

Ravi Teja said...

Helpful. Any specific reason to use two different AMs? I think in this example even if the two regions use same AM's data controls, the solution works as intended. As there is no navigation from one TF to other TF, Shared DC property doesn't matter. Each TF have their separate data control frames. So Please confirm if there is any specific reason to use two different AMs to achieve the mentioned requirement and will it work as intended if two TFs bindings based out of single AM? Thanks.