ORACLE ADF
Contextual Events is an Oracle ADF feature
that enables developers to implement
view-to-region, region-to-view, and region-
to-region communication.
Right-click EventHandler.java in the
Application Navigator and choose Create Data
Control. This step exposes the event handler
methods in a JavaBean data control. Next
select the DataChangeDisplayPageDef.xml
file entry in the adf.sample.oramag pageDefs
package and select View -> Structure from the
main menu. In the Structure window, right-click the bindings node and choose Insert
Inside Bindings -> Generic Bindings ->
methodAction. In the Create Action Binding
dialog box, select the EventHandler data
collection and choose one of the two event
handler methods in the Operation list. Click
OK, and repeat the same steps for the other
method. In the Structure window, expand the
two method bindings you’ve just inserted and
note that each has a customPayLoad argument, as shown in Figure 1.
Next you’ll deploy the contextual event
consumer in an Oracle ADF library. In
the Application Navigator, right-click the
Mirror TaskFlow project and choose Deploy
-> OraMagMirror TaskFlow. Then click Finish
in the Deployment Action dialog box. The
Oracle ADF library JAR file is created in the
project’s Deploy folder.
use this name later to identify the producer
event when mapping it to the event handler.
The Raise Condition tab enables you to enter
an expression language (EL) expression
defining a condition under which an event
is propagated. On the Documentation tab,
you can enter a text description of the event
producer; the description is visible when you
map the producer to event handlers. Leave
the Raise Condition and Documentation tabs
unchanged, and click OK.
DCBindingContainerValueChangeEvent
is the event object class that is passed for
Oracle ADF–bound value changes. (If an
input field is not Oracle ADF bound, the
payload object will be javax.faces.event
.ValueChangeEvent.)
In the Application Navigator, select the
DepartmentsViewPageDef.xml file in the
adf.sample.oramag.vi
ew.pageDefs package
and open the Structure window. Expand the
bindings -> DepartmentName node to see the
event definition you created for this attribute.
Now you’ll create a second producer
event—one with a custom payload. In the
visual editor for the DepartmentsView.jspx
file, click the Submit Custom Payload button
and create a new contextual event from the
Contextual Events category in the Property
Inspector’s Behavior section. Enter
commandActionCustPayLoad for
Name. Check the Pass Custom Value from
box. Choose the Page Data option, and
select the ManagerId entry, as shown in
Figure 2. By doing so, you’re overriding
the default payload object (javax.faces
. event.ActionEvent) and replacing it with
the ManagerId value. Click OK to create
a new eventBinding definition of type
javax.faces.event.ActionListener in the
DepartmentsViewPageDef.xml file. This contextual event will fire when a user clicks the
application’s Submit Custom Payload button.
The eventBinding is referenced from the
button’s ActionListener property with expression language: #{bindings.eventBinding
Figure 2: Creating a contextual event producer with a
custom payload
. listener.processAction}. Developers can also
invoke contextual events from Java code in a
managed bean by casting the eventBinding
reference to JUEventBinding and calling the
getListener method.
CREATING PRODUCER EVENTS
Now you’ll switch to a different project and
create two contextual event producers. Open
the OraMagMirror TaskFlowConsumerApp.jws
workspace, located in the starter-app folder.
First you’ll create a producer event
without a custom payload, so that the event
object will become the payload by default.
In the Application Navigator, double-click
the DepartmentsView.jspx file in the View
Controller project. In the visual editor, select
the DepartmentName field and open the
Property Inspector. In the Property Inspector,
open the Behavior node, scroll to Contextual
Events, and click the green plus (+) icon
under the Published Events header.
Select Create New Event, and enter
departmentNameChange for Name. You’ll
ADDING REGIONS FROM THE ORACLE ADF
LIBRARY TO THE APPLICATION
Now you’ll add the event handler regions
to the sample application. The first step is
to create a Resource Catalog file connection to the Deploy folder holding the Oracle
ADF library JAR file you created earlier.
Choose View -> Resource Palette from the
main menu, and click the folder icon at
the top. Choose New Connection -> File
System, create a connection with the name
Oramag TaskFlow, and then browse to the
starterapp/mirrortaskflow/deploy folder to
fill in the directory path. In the Application
Navigator, select the ViewController
project. Then, in the Resource Palette,
expand the file connection and select the
OraMagMirror TaskFlow.jar library, making
sure the ViewController project is still
selected in the Application Navigator. Right-click the library and choose Add to Project. In
the Confirm Add ADF Library dialog box, click
Add Library.
With the DepartmentsView.jspx file open
in the visual editor, open the Component
Palette and select OraMagMirror TaskFlow.jar