Saturday, November 6, 2010

ADF UI - Region Interaction: From parent page to child region task flow

If you drop a task flow as a region in a jsf page and if you want to refresh the task flow region based on some action in the jsf, please go through this post.

Sample UseCase:
For example if a Jsf Page contains departments table and on selecting a department from the table and click on button 'Show Employees', it should display the employees in the selected department. But suppose the employee details should come from a different task flow. We need to establish the communication between the parent jsf page and the task flow region in it. Sample application for this example can be downloaded from here.

Implementation Steps:

Task flow refresh Principle:
If you drop a task flow that takes some parameters as a region in a jsff page, the task flow binding will be added in the pagedef file. If you set refresh='ifNeeded' for the task flow binding, the task flow will be re-executed each time when the value for one of the passed parameters got changed. To be clear, here re-execution means the task-flow will re-execute from it's default activity in the task flow diagram.

This example depends on the above principle.

1. Create a jsff page and include departments table and add a button 'Show Employees'.
2. Create a task flow that takes deptId as parameter and fetches the employees present the given department and shows them in a table.

Task flow diagram with input parameter deptId:

3. Specify actionListener for the 'Show Employees' button and in the actionListener method, get the deptId selected in departments table and set to to a pageFlowScope variable.

Java bean containing the actionListener method for 'Show Employees' button:
public class ExampleBean { private Integer deptId; public void buttonClicked(ActionEvent ae){ Row currentDeptRow=(Row)ADFUtil.evaluateEL("#{bindings.DeptVO.currentRow}"); ADFUtil.setEL("#{pageFlowScope.deptId}",currentDeptRow.getAttribute("Deptno")); } public void setDeptId(Integer deptId) { this.deptId = deptId; } public Integer getDeptId() { return deptId; } }

4. Drop the employee details task flow as a region in the jsf page. Pass the same above pageFlowScope variable as a parameter to the dropped taskflow. Specify refresh="ifNeeded" for the task flow binding in pagedef.

Task flow binding in the pagedef:

   <taskFlow id="TaskFlow21"               taskFlowId="/com/demo/taskflows/TaskFlow2.xml#TaskFlow2"               xmlns=""               Refresh="ifNeeded" activation="deferred">       <parameters>         <parameter id="deptId" value="#{pageFlowScope.deptId}"/>       </parameters>     </taskFlow>

That's it. This is how it works: When the user selects department in jsff and clicks on 'Show Employees' button, the actionListener method sets the pageFlowScope variable with the deptId selected and the same will be passed to the dropped task flow. As the task flow re-executes if any of it's input parameter changes, the employees will be queried based on passed deptId and the task flow will refreshed with the corresponding employee details. No 'partialTriggers' is required in this case. Refresh of task flow will be triggered automatically when the input parameter value is changed.

Sample screen shots:


  1. Very useful post. Is it possible to do it the other way round though? Is it possible to refresh the parent page from the action listener in the task flow?

  2. Yes, it's possible to refresh the parent page from child task flow using contextual events. The above principle won't work for child-to-parent interaction. How to use contextual event framework to achieve the same will be posted soon :)

  3. thanks for the post
    but can you upload the dump file or script to the tables used in the project as i don't have this schema

  4. This example is based on SCOTT schema.. It should be available in Oracle by default.

  5. Two questions (appreciate your response):
    1. What if the detail taskflow is in a separate region in another page and the page needs to be bookmarkable?

    2. If the detail taskflow itself has nested details links, i.e. show employees (in another dept) button in the details page, would this work? along with browser back button showing correct details as you click back button?

  6. excellent adf tips. keep posting the useful.


Related Posts with Thumbnails