Long time ago, back in early 2007, I had a blog post about JSF Page Templates - Templating in Oracle JDeveloper 11g. First technical preview for JDeveloper/ADF 11g was just released and it was my first blog post about 11g version. It was exciting time - I was writing it while flying somewhere between Norway and Denmark. We keep forgetting good things and remember only bad, but just think about - JDeveloper 11g is referencing ADF libraries from ADF Runtime module, but in 10g we were copying these libraries into every application, WEB-INF folder. Yes..., I'm happy to work with 11g.
Today I will return to JSF Page Template topic and will describe how you can apply it for JSF Page Fragments and improve reusability across your system. Typically we apply JSF Page Template for JSF Pages, but there are many use cases when templates can be applied for JSF Page Fragments (when using ADF Regions). Download sample application - FragmentTemplate.zip.
This application implements JSF Page Template with Query Criteria and area for results data:
JSF Page Template is mapped with Page Definition for Query Criteria executables:
As you already know, Query Criteria returns search result into component defined by Result Component Id attribute. Result data collection will be defined inside JSF Page Fragment created based on our template. This means, from consuming JSF Page Fragment we need to pass information about Result Component Id into JSF Page Template and define it for Query Criteria:
JSF Page Template must declare attribute for Result Component Id, to pass value from consuming JSF Page Fragment:
This attribute will be referenced from Query Criteria:
Application implements two JSF Page Fragments, each of them is based on JSF Page Template with Query Criteria. One JSF Page Fragment provides simple Search form, another Master-Detail relationship:
If we want to preserve JSF Page Template Query Criteria parameters, when switching between different JSF Page Fragments - Query Criteria VO implementation class needs to be overridden:
Override executeQuery() method, and call saveState() function to ensure that Query Criteria parameters are saved when we are navigating between different instances of the same Query Criteria:
Main page contains two tabs, each tab renders different JSF Page Fragments, these fragments are implemented based on JSF Page Template. Query Criteria is coming from JSF Page Template:
This allows to reuse the same Query Criteria for different JSF Page Fragments. For example, user can search:
Open another JSF Page Fragment with Master-Detail and use the same Query Criteria - no need to implement it twice:
Perform another search:
Same Query Criteria will be applied again, now for the first tab: