Académique Documents
Professionnel Documents
Culture Documents
Contextual Events
Abstract:
Contextual Events is an ADF Framework feature that allows developer to etsablish communication between two independent ADF Region. In this hands-on you create a contextual event between a region displaying a DVT graph component and a region displaying a table. You will set up the contextual event manually on the binding layer and also write some Java code that helps preserving the default click behavior on the graph. Duration: 45 minutes
2010 / 2011
Introduction
The contextual events framework in Oracle ADF defines a publish / subscribe mechanism that leverages the ADF binding layer to notify ADF Regions about user interaction performed in other regions, the parent page or a ViewPort (page fragment). Oracle JDeveloper provides declarative help to setup contextual events for input and action components, but not yet for DVT components like graphs. Setting up a data visualization component (DVT) to publish contextual events is more challenging than from an input text field or a table, but it is a good use case to understand how contextual events work. The image below shows the application you build in this hands-on. The DVT graph component is selectable and allows users to click on the graph bars. Clicking on a bar does set the current row on the underlying ADF binding, making sure the read only form displays the detail information for the selected bar. At the same time, a contextual event is raised and published to the ADF Region containing the employee table. The contextual event payload allows a managed bean to access the selected department Id and query the business service for employees working in it.
Note: This hands-on is created to focus on the ADF Contextual Event functionality. The UI is functional and no time is spend on making it look beautiful.
To shorten the time it takes to build the hands-on sample, the two bounded task flows and managed beans were pre-created. In addition, a Java class is provided in the adf.sample.view.ctx package that receives and handles the event broadcasted by the event producer. In the first section of this hands-on, you set up the contextual event producer, consumer and the event mapping. In the second part, you go advanced and invoke the contextual event from Java. 1. Expand the adf.sample.view.pageDef package and select the BrowseDepartmentsPagedef.xml file, which is the ADF binding file of the page fragment containing the DVT graph component. The ADF binding file will become the event producer
2. Open the Structure Window (ctrl+shift+S) 3. Select the "bindings" node and choose Insert inside bindings | Generic Bindings | eventBinding to create a new ADF event entry
4. Select the eventBinding entry you just created and choose Insert inside eventBinding | events from the context menu. An event binding can contain multiple events that can be mapped to different event consumers.
5. Select the "events" node and use the right mouse to open the context menu 6. Choose Insert inside events | event from the menu to create a new event item
9. Select the "eventBinding" node 10. The "id" property is accessible from EL and Java, as we show later. For now, just set it to "ChartDrillEvent" 11. In the "Listener" property field, type oracle.adf.view.faces.bi.event.ClickListener Its the listener class that matches the click event of the DVT component that is used in this hands-on to invoke the contextual event producer
14. After the DataControl configuration is generated by Oracle JDeveloper, double click the ContextualEventHandler.java file to open it
19. Select the "ContextualEventHandler" Data Control. 20. Ensure the "handleEvent(Object)" method is selected 21. Press "Ok"
23. Drag the "dvt-task-flow-definition.xml" task flow from the Application Navigator and drop it into the first facet of the Panel Splitter component in the ParentContainer.jspx file
25. Drag the "employees-task-flow-definition.xml" task flow from the Application Navigator and drop it into the second facet of the Panel Collection in the PanelContainer.jspx file
26. Select "Region" in the opened context menu to create a static ADF Region
27. The employees task flow requires an input parameter for the initial query of the employees. Click into the parameter field
10
29. Press OK. When the task flow loads the first time, its page fragment shows a list of employees working in department 10
30. Select the ParentContainerPageDef.xml file in the adf.sample.view.pageDefs package 31. Open the Structure Window
11
33. Select the ParentContainerDef root entry again and choose "Edit Event Map" from the right mouse context menu
33. In the opened Event Map Editor, press the green plus icon to create a new event mapping
12
35. Select the BrowseDepartmentsPageDef.ChartDrillEvent entry and double click on it to close the list
13
38. Press the green plus icon to create a new entry in the Consumer Params
39. Define a new parameter with the Param Name payload and the Param Value ${payLoad}. Note that the parameter name "payload" matches the name of the argument in the event handler method. The ${payload} EL access the event message, which is the event object if no custom payload was defined.
14
15
44. In the Property Inspector, note the current Expression Language string added to the "ClickListener". When creating a DVT component graph, you can check a checkbox to make a click on a bar in the graph to mark the underlying row as selected in the ADF binding. In response to checking the check box, the EL string is added to the Click Listener property. 45. Select the Expression Language string as shown in the image below and copy it into the clipboard for later use. To invoke a contextual event in response to a user clicking onto a bar in the graph, while preserving the configured behavior to mark the underlying row as current in the binding, you will replace the EL string with a managed bean method reference.
16
46. Click the arrow icon next to the "ClickListener" property field and choose "Edit" from the context menu.
17
51. Double click onto the DepartmentBackingBean.java file to open it in the code editor.
18
54. Type or copy the following code lines into the method
19
Note: Oracle JDeveloper needs to import classes for the code to work. Either manually import the classes, or copy and paste the following lines to the top of the Java file (but still below the package name)
import import import import oracle.adf.model.BindingContext; oracle.adf.view.faces.bi.event.ClickListener; oracle.binding.BindingContainer; oracle.jbo.uicli.binding.JUEventBinding;
The code lines above access the ADF Binding Context to access the Binding Container at runtime. It then looks up the "ChartDrillEvent" binding to access and invoke the ClickListener 55. Select the PageContainer.jspx file and choose "Run" from the right mouse context menu
20
56. In the opened page, click onto a graph bar and watch the read only form and the table refreshing.
RELATED DOCOMENTATION
21