Skip to main content

Programmatically publishing Contextual Events

ADF task flows provide modularity to the web applications. Bounded task flows are really useful while realizing business use cases, which may repeats across application(s). Please refer Fusion Developer's Guide if you want to know more about this topic. Bounded task flows are added to the page as regions. It is very common that one region may need to communicate with other regions. This is accomplished by Contextual Events. To know more about Contextual Events, please refer Creating Contextual Events.

There are scenarios where task flows may need to raise the Contextual Events based on complex business conditions. Declarative event handling mechanism might not be sufficient in this case. Now the question is how to raise 'Contextual Events' programmatically from backing bean? Let me try summarizing the steps below. Please refer the Fusion Developer's Guide for detailed explanation on creation of Contextual Event.

1. Create the Producer (Payload) Method
2. Bind the Producer Method with task flow, which raises the event
3. Create the Consumer (Handler) Method
4. Map the Contextual Event i.e.: tell the system to use above defined Consumer for a specific event Producer

Once the above infrastructure is in place job is pretty simple. The below code snippet will help you to publish Contextual Event programmatically from the backing (managed) beans. Typically the below code may goes to the action handler methods defined in the backing bean.

DCBindingContainer bc = (DCBindingContainer)BindingContext.getCurrent).getCurrentBindingsEntry();
JUCtrlActionBinding actionBnd =
((DCBindingContainer)bc).getEventDispatcher().queueEvent(actionBnd.getEventProducer(), parameter)

You can download the sample workspace from here.


Edwin Biemond said…

Is this also possible without making a dummy producer method in the pagedef and passing your own payload.
Frank Nimphius said…

you don't need a producer method. You can also create a producer that response to JSF events like ActionEvent or ValueChangeEvent.

The upcoming version of JDeveloper 11g has a PropertyInspector option for contextual events that makes this part simple and easy
Jobinesh said…
Thanks Frank for the comments.

As Frank pointed out, we really don't need producer method, even a simple 'event bidning' can form ContextualEvent.
Anwar said…
This comment has been removed by the author.
Anwar said…
Can a table selection listener raise a contextual event ? If it is possible, can that method raise a contextual event programatically ?
Jobinesh said…
Hi Anwar
Yes,You can define contextual event for a table selection change AKAS currency change (I assume you use 11gR1PS1 release) Select the table and define the event.
Anwar said…
Thanks Jobinesh..I am using 11gR1PS1. But when I select the table and click on the add event button, the dialog appears without having the evenType populated by default. I have seen that in your example and the example Frank has on ADF Code, the dialog is populated with event type. Is this something wrong with my installation or a bug ?
Jobinesh said…
I can see this working in my local copy(11gR1PS1). Not sure why this doesn't work for you. In worse case, you can try key in the eventType="Currency Change Event".
Vinit said…
Is there a way to extract the event from the pageDef of the view within a bounded taskflow? I observed this extracts the action bindings from the top level unbounded taskflow. Thanks.
Jobinesh said…
Can you detail the use case ? Are you interested to identify the event source? if yes, take a look at this post, May give you some idea on this part.
Hasim said…
Hey Jobinesh,

There is a bug associated with table selection contexual event.

there is a bug 10045872 filed for this. The bug is scheduled for fixing in PS4 ( I'll work on a manual - though code centric - alternative for the time being and publish it on ADF Code Corner when done.
cong said…

How can I do publish contextual events with an action on af:commandToolbarButton? I tried to follow your advice but I couldn't find "contextual events" under "Behavior" for commandToolbarButton.

Jobinesh said…
Its missing currently. However you can either build the binding from the binding editor(click on binding tab) or as a work around select a commandButton, use the editor for creating contextual event and map the same to af:commandToolbarButton

Popular posts from this blog

How to set Bind Variable Values at runtime ?

In this post I'm sharing a couple of approaches for programmatically setting bind variables values at run time. This post is an attempt to explain 'When to use what ?'[ In case if you are familiar with 'Bind Variables' in ADF BC, please refer Section 5.10, Working with Bind Variables in Fusion Developer's Guide ]

1. Set the Bind Variable value using RowSet::setNamedWhereClauseParam(...)

You can use use the setNamedWhereClauseParam(...) method on the ViewObject interface (which extends oracle.jbo.RowSet) to set the value for bind variables. Please note this sets the value on default RowSet. In other words, this doesn't have any effect on the secondary RowSets that you/system generates.
ViewObject vo = am.findViewObject("EmployeesView1"); vo.setNamedWhereClauseParam("bindVarDeptId", new Number(10)); vo.executeQuery();
2. Set the Bind Variable value using ViewObject's VariableValueManager::setVariableValue(...)

VariableValueManager Ma…

Happy New Year 2018 !

We can't go back and change the beginning, but we always can start where we are and change the ending. Believe in yourself and you will be unstoppable!

Wishing you and your family a very happy new year 2018 !!!