FROM THE BLOG

ADF Tutorial: How to publish contextual events from a tree selection?

Let’s imagine the following scenario; or even better, let’s see the following picture:

tree_contextual_events_adf_oralution_oralublog_01

We’ve got a home page with an embedded taskflow being shown as a region. When we select a node from the tree, we want to communicate to the Home Page that the selection has been made, passing also data in the form of a payload.

Searching in google you might have got to this corner case; about raising an event from a graph click selection. Our post is very similar with some few changes. Let’s get into it.

The first thing to do is to go to the page definition where we want to raise the event and create a new event binding

tree_contextual_events_adf_oralution_oralublog_02

 

Then we need to specify a name and the important bit, what is going to be the listener on this events. In our case, a tree selection triggers a org.apache.myfaces.trinidad.event.SelectionListener.

tree_contextual_events_adf_oralution_oralublog_03

Then we proceed to add a Events field and inside the event we will raise:

tree_contextual_events_adf_oralution_oralublog_04 tree_contextual_events_adf_oralution_oralublog_05

 

Here we give a name for the event and what do we want to pass to the consumer on its payload. It can be anything (java Object). In this case we will pass the EmployeeId concatenated by a ‘_’ following with the Employee Last Name. We will show how to put the values in those pageFlowScope variables.

tree_contextual_events_adf_oralution_oralublog_06

 

By default, our tree selection listener is set to execute our bindings iterator makeCurrent method. We will override this by creating a backing bean and creating a custom selection listener method:

tree_contextual_events_adf_oralution_oralublog_07

 

 

The following code was taken from this article which describes how to get the current tree’s node from its selection listener. For some reason, this component doesn’t recognize client attributes so so far, this is the only way we could get the current node. If you know a cleaner way, please let us know.

 

tree_contextual_events_adf_oralution_oralublog_08

The setExpressionValue has the following code:

tree_contextual_events_adf_oralution_oralublog_12

Now, we are set to configure the contextual events and see our solution in action. Last year, we wrote about how to use contextual event without creating a POJO Datacontrol only for this purpose. It is kind of a trick since there is no declarative way to select a method from a bean and expose it in your data control that way. However, if you do it manually it works. Here is the article.

This is the code from our Home Backing Bean that we want to execute when the tree selection happens:

tree_contextual_events_adf_oralution_oralublog_09

 

Once we set this method using the strategy described on the article before we can proceed and set up the contextual events as follows:

 

tree_contextual_events_adf_oralution_oralublog_13

 

Now, running our page and clicking on the nodes of our tree will fire the events and will be consumed by our method in our home bean, adding a message and partial triggering the tab to refresh its content:

tree_contextual_events_adf_oralution_oralublog_10 tree_contextual_events_adf_oralution_oralublog_11

Leave a comment

Your email address will not be published. Required fields are marked *

Social Media

Stay up-to-date with our latest ADF and related technical posts via your favourite social network services.