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:

9 comments:

leslie martinez 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

Andrejus Baranovskis 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

Sebastian Mieszczankowski 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

Andrejus Baranovskis 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

Sebastian Mieszczankowski 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

Andrejus Baranovskis said...

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

Regards,
Andrejus

Alejandro Tovar Lanz said...

Hi Andrejus,

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

Regards

Andrejus Baranovskis said...

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

Andrejus

aravindpattar 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?