Tuesday 4 June 2013

Bean reference technique to enable Oracle Application Development Framework regions to make callbacks to their parent pages. Part 2

Overriding the Departments Table Selection Listener

Now that the departments task flow is configured, the next step is to wire up the table with the managed bean in pageFlow scope. This step will enable selected row data to pass to the parent page whenever a user selects a table row in the user interface. To perform this task, you need to override the SelectionListener of the table, as shown below. 1. In the task flow diagram that shows the contents of the departments-task-flow.xml file, double-click the DepartmentsView activity to open the page. 2. In the page editor, click the af:table#t1 bread crumb at the bottom of the visual editor window to select the table. 3. In the Property Inspector, navigate to the SelectionListener property within the Behavior category. If the Behavior category is not yet expanded, expand it by clicking the + icon. 4. Click the down-arrow icon on the right-hand side of the SelectionListener property field, and choose Edit from the context menu to bring up the Edit Property: Selection Listener dialog box. 5. Select departmentsFlowBean from the Managed Bean list. 6. Click the New button next to the Method field to create a new managed bean method to handle the selection event. 7. In the Create Method dialog box, define the MethodName as onRowSelect and click OK twice. 8. Select the DepartmentsPageFlowBean .java tab, the first tab in the Oracle JDeveloper code editor area. (This is the first file you opened in this tutorial.) 9. Navigate to the onRowSelect( SelectionEvent selectionEvent) method, and place the cursor within the code braces. 10. Add the following code to invoke a precreated method on the bean’s superclass: 11. super.onRowSelect(selectionEvent, parentHandle); 12. Save your work, and close all opened tabs by clicking the x at the right side of each. In this section, you changed the default row selection behavior, and by doing so, you synchronized the table selection with the Oracle ADF binding layer to invoke a method on the managed bean superclass. The onRowSelect method of the superclass does two things: it synchronizes the user row selection with the binding layer, and it notifies the parent task flow bean about the selection change. To handle these tasks, it uses the parentHandle variable you passed in as an argument. Configuring the Parent Task Flow Bean In this sample application, the managed bean that dispatches the messages sent from the regions to the parent page is configured in the unbounded task flow definition (adfc-config.xml). To build and configure the managed bean, follow these steps: 1. In the ViewController project, expand the Application Sources folder and navigate to the beans package node within the oramag.mayjun.thirteen.view node. 2. Right-click the beans node, and choose New from the menu that appears. 3. In the New Gallery dialog box, select the General -> Java node. 4. From the right-hand list, select Class, and click OK. 5. In the Create Java Class dialog box, add the Name field value ParentPageBean. 6. In the Package field, append .parent to the current package name so it reads oramag.mayjun.thirteen.view .beans.parent. 7. In the Optional Attributes section, click the green plus (+) icon next to the Implements label to implement an interface class. 8. In the class and package browser, switch to the Hierarchy tab (if it’s not already selected) and navigate to the oramag -> mayjun -> thirteen -> view -> beans -> interfaces package node. 9. Expand the interfaces package node, and select ParentHandle. Click OK twice. 10. Save your work. In this section, you created the managed bean for the parent task flow and implemented the ParentHandle interface, which defines the communication contract between the region and the parent bean through the notifyParent method. If you use this technique in your custom Oracle ADF application projects, you can define additional methods. Next, add the implementation code to the managed bean so that the parent page updates whenever the regions pass data. 11. Expand the ViewController -> Resources node in the Application Navigator, and double-click ParentPageBean.txt. 12. Copy the contents of the ParentPageBean.txt file to the clipboard by pressing Ctrl + A followed by Ctrl + C. 13. Copy the contents of the clipboard to the ParentPageBean.java class by selecting the ParentPageBean.java tab, clicking in the class, and pressing Ctrl + A followed by Ctrl + V. 14. Save your work, and close all tabs. Next, configure ParentPageBean.java as a managed bean in the parent task flow (adfc-config.xml). 15. In the Oracle JDeveloper Application Navigator, expand the ViewController -> Web Content -> WEB-INF folder and double-click the adfc-config.xml file. 16. In the opened adfc-config.xml diagram, click the Overview tab at the bottom. 17. Select the Managed Beans menu entry, and click the green plus (+) icon next to the Managed Beans label. 18. Click in the Name field, and change the default name to ParentPageBean. 19. Click in the Class field. Click the down-arrow icon on the right, and select the Edit menu entry to open the class browser. 20. In the Edit Property dialog box, switch to the Hierarchy tab (if it’s not already selected). 21. Navigate to and expand the oramag -> mayjun -> thirteen -> view -> beans -> parent package node. 22. Select the ParentPageBean class, and click OK. 23. Finally, for the Scope field value, select view from the list. 24. Save your work. Adding the Regions to the Parent Page Next Steps DOWNLOAD Oracle JDeveloper 11g the sample application for this article LEARN more about contextual events “Implement Contextual Events” “Master and Commander” Almost there! The next step is to add the departments task flow (departments-task-flow.xml) and the employees task flow (employees-task-flow.xml) to the ParentPage.jsf file as a region. Note that the employees task flow has been fully precreated for this tutorial, so there is no need for you to build it first. To perform this task, you need to pass the ParentPageBean managed bean reference as an input argument to the region to set up the communication link. 1. In the Application Navigator, expand the ViewController -> Web Content -> pages double-click ParentPage.jsf. The file will open in the visual editor. 2. Expand the ViewController -> Web Content -> WEB-INF -> btf folder. 3. Drag and drop the departments-task-flow.xml file into the Departments Region area in the visual editor, as shown in Figure 3. Figure 3: Creating the departments region 4. In the opened Create dialog box, select the Region menu entry. 5. In the opened Edit Task Flow Binding dialog box, click in the Value field with the red border around it. (If you don’t see this dialog box, you most likely forgot to check the required checkbox for the task flow input parameter as explained in step 33.) 6. Click the down-arrow icon, and choose Expression Builder from the menu. 7. In the Expression Builder dialog box, expand the ADF Managed Beans -> viewScope node and select ParentPageBean. 8. Click OK twice to create the region. 9. Repeat steps 71 through 76 for the employees-task-flow.xml task flow definition, but drop it in the Employees Region page area. Save your work. Running the Sample The ParentPage.jsf page contains an output text box for displaying the region ID of an incoming message as well as an af:forEach Oracle ADF Faces tag to print the message sent from the bounded task flow. Both UI components of the Oracle ADF Faces feature of Oracle ADF reference the ParentPageBean managed bean, which is why it was important that you used the names suggested in this tutorial. Run the page by following the steps below: 1. In the Application Navigator, expand the ViewController -> Web Content -> pages node and right-click the ParentPage.jsf page. 2. Choose Run from the menu that appears. 3. Once the page is displayed in the browser, select a row in the departments table or the employees table that is not currently selected to see the region-to-parent-page communication shown in Figure 2. Conclusion This article explained a technique for establishing region-to-parent-page communication by using a managed bean reference. Although the article doesn’t cover it, you can also extend this technique by using the parent task flow as a dispatcher to implement bidirectional region-to-region interaction—a testament to the power of this approach. By using bounded task flow templates to define the bounded task flow input parameter and managed bean, you can make the bean reference technique a part of your overall task flow design strategy. This approach adds a powerful new tool to your Oracle ADF toolbox.

2 comments:

  1. Nice post...I look forward to reading more, and getting a more active part in the talks here, whilst picking up some knowledge as well..

    Pass Box manufacturers

    ReplyDelete
  2. Very informative ! Indian cyber Army gives Best Ethical Hacking Training in noida in view of current industry principles that causes participants to anchor positions in their fantasy occupations at MNCs.

    ReplyDelete