Thursday, July 26, 2012

Refreshing ADF Page Template from ADF Fragment Template

I had a blog about how to refresh ADF template content from fragment - ADF Page Template Refresh From ADF Page Fragment. There I was describing you can apply Partial Trigger to the template. There is another scenario for template refresh. Let's say we have two templates - page and fragment templates. Those two templates are completely unrelated on design time and only on runtime are rendered as one. When building custom UI Shell, you may require to refresh components available in page template from fragment template. How to do this - if two templates are just separate files and there are no references. Well - keep in mind on runtime all templates are just one JSF tree. This means we can reach Page template from nested Fragment template through JSF tree. I will describe how.

Download sample application - TemplateRefreshApp_v2.zip. This application is simple use case for potentially more complex implementations. Page template contains two tabs, fragment template contains Switch button. This button allows to manage tabs from page template and switch between tabs.

Sample application contains two fragments, implemented based on fragment template. There is main page, it is implemented based on page template:


Page template implements two tabs - each tab contains facet definition. Later we drag and drop regions into these facets:


Fragment template contains Switch Tab button and facet definition for content:


Fragments are based on fragment template:


Main page is based on page template and includes two regions:


I will describe now how refresh between fragment and page templates is implemented. Root component from fragment template - panel stretch layout, contains binding reference:


Binding reference points to the fragment template bean - the same bean, where refresh method is implemented:


Here is main part now - refresh method. This method firstly gets panel stretch layout binding instance and retrieves parent of this component. Parent will be UI template component - fragment template tag. But it doesn't end here - you can get next parent - parent of UI template. Its how you will move into the area of page template - it surrounds fragment template. It will return instance of the tab, if you get parent of the tab - it returns panel tabbed UI component. With panel tabbed, its easy to iterate over tabs from page template and set disclosed property. Once disclosed property was set, we perform partial refresh of page template from fragment template:


Here is how it looks on runtime - two tabs from page template, Switch Tab button from fragment template and finally region content included through fragment template facet:


Press Switch Tab - current tab will be closed, second tab will be opened:


Fragment template is able to refresh page template by acquiring instance of page template UI components through JSF tree.

6 comments:

rnvprasad said...

Hi Andrejus,

I have a small doubt, regarding the PPR of child components in PT(Page Template). You said its enough to keep the partial triggers on the PT to refresh the child components in your earlier post http://andrejusb.blogspot.com/2012/02/adf-page-template-refresh-from-adf-page.html. But in the Oracle Fusion Developer Guide by Frank and Lynn, in the Page 481, they clearly stated that if we need to refresh the child components we need to place partailtiggers on the child components to the value of the partialtriggers attribute of the PT. Please let me know whether we need to follow these 2 approached based on the type of child components or not. Thanks.

N.

N said...

Hi Andrejus,

Please check the page 481 in the Oracle Fusion Developer Guide by Frank and Lynn, the book is contradicting your statements in your earlier post http://andrejusb.blogspot.com/2012/02/adf-page-template-refresh-from-adf-page.html
The book says we need to keep partialtriggers on the child components also, in order to refresh them. Please clarify on this. Thanks.
N.

Andrejus Baranovskis said...

Hi,

Those are different use cases, nothing is contradicting.

In this post I'm describing how to refresh Page Template from Fragment Template. Those are two completely different components and you can't set declarative Partial Trigger - there is simply no relationship.

Previous post you are referencing, again is different use case. Its doing declarative PPR on Fragment Template from Fragment (no Page Template there).

Keep in mind - there is no declarative access to page/fragment template components from consuming page/fragment.

Hope this makes it more clear.

Regards,
Andrejus

Anonymous said...

Is that possible use a page fragment in a template?
assume you have a common header and need to add it to different termplates

Don Kleppinger said...

I believe it is possible to add a declarative partial trigger by inspecting the element at run time using firebug to view the componet ID and determine the component path then add that to the partial trigger value. Even though it will display underlined in red because it can't be found at design time it will work at runtime.

Andrejus Baranovskis said...

This is not dynamic approach and it will not work for ADF regions. Because region ID in HTML source is not static.

Andrejus