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="http://xmlns.oracle.com/adf/controller/binding"               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:

13 comments:

  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?

    ReplyDelete
  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 :)

    ReplyDelete
    Replies
    1. I am looking for the exact same scenario to refresh the parent page from child task flow using contextual events.

      Could you pls share that information

      Delete
  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

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

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

    ReplyDelete
  6. excellent adf tips. keep posting the useful.
    thanks.

    ReplyDelete
  7. As parents, we often think that we don't need a parents guide, that we should instinctively know how to discipline our kids, end tantrums, etc. The reality is that the great majority of parents do need a parents guide because parenting has to be learned! In this short but hopefully helpful parents guide, I'm going to give simple but essential dos and don'ts that any parent should know and apply. parenting teens info

    ReplyDelete
  8. With Himalaya's range of baby care products you can rest assured that you are giving the best to your little angels. Parenthood is a time when you have to bear an extra responsibility and you cannot run from them. From massage oils to baby wipes, there is a complete array of head-to-heel products for babies. The company arranges these products under three categories - pre-bath, bath and post-bath. Babies are massaged before bath to help develop their muscles and to stimulate body growth, so massage oils are considered pre-bath product. Massaging the body with oils can also help beat dry skin, which can be a concern for parents. Similarly, those products that are used while bathing babies are called bath products. This category includes gentle baby shampoo, gentle baby bath, gentle baby soap, extra moisturizing baby soap, refreshing baby soap and nourishing baby soap. baby crib

    ReplyDelete
  9. An overview of some of the most popular pregnancy books available today. Many reviews are available on my site at best books on pregnancy. Prams U.K.

    ReplyDelete
  10. Having a new baby is a very grand thing. Thus, as a parent it is but important for you to be really conscious and aware of the numerous risks that might put the safety of your newborn into a compromising situation so that you can effectively counteract it with appropriate safety equipments. Baby cribs, cabinet latches, baby safety harness and child safety locks are just a few of the safety products made available in the market. baby safety

    ReplyDelete

Related Posts with Thumbnails