Skip to content
June 5, 2014 / Amaro Bica

How to pass complex payload in programmatic Contextual Event launch

In Oracle ADF applications, sometimes we need to trigger Contextual Events programmatically on action listeners or another kind of listeners because some ADF Faces components don’t have out of the box Contextual Event configuration through Property Inspector. Rich Command Menu Items, Rich Command Navigation Items and Rich Command Buttons are some examples of these components.
In most of the cases we want to pass a complex payload with information about the Contextual Event. How to pass it?

Solution

The solution is to pass a class that represents the payload, instantiate it on launching the event and casting to it on handling. In this tutorial I created a page with two regions:

  • a top region that contains a menu that launches the event with information about the button pressed and a value of an inputText
  • a bottom region that catches the event updating an outputText.

Download here CEPayload.zip .

Payload class

First you have to create a Java class representing the payload. In the provided example, it’s being passed a color and a username:

package pt.linkconsulting.cepayload.payload;

public class MenuEventPayload {

    private String color;

    private String username;

    public MenuEventPayload() {

        super();

    }

    public MenuEventPayload(String color, String username) {

        super();

        this.color = color;

        this.username = username;

    }

    // getters and setters

    ...

}

Publisher

Before launching the Contextual Event, you should publish it on publisher’s page definitions as usual like in the following example:

1-publish

Then in the event listener method of the publisher side you must import that class and include the following code:


//get the eventBinding and its dispatcher
JUEventBinding eventBinding =
    (JUEventBinding)BindingContext.getCurrent().getCurrentBindingsEntry().get("eventBinding");

EventDispatcher eventDispatcher =
    ((DCBindingContainer)BindingContext.getCurrent().getCurrentBindingsEntry()).getEventDispatcher();

// create the payload
MenuEventPayload menuEventPayload =
    new MenuEventPayload(color, username);

eventDispatcher.queueEvent(eventBinding, menuEventPayload);

Subscriber

In the subscriber side, do the usual job to handle Contextual Events, except in the last step.
Create a Data Control from the class with the method that will handle the event:

2-datacontrol

Register the method in the bindings:

3-handleevent

Register the in page definition’s event map:

4-eventmap

And finally you must import your payload class and cast the argument to it:


public void handleEvent(Object payload) {

    MenuEventPayload menuEventPayload = (MenuEventPayload) payload;

    String color = menuEventPayload.getColor();

    String username = menuEventPayload.getUsername();

    // use these parameters to update your subscriber region

    ...

}

Now you are ready to run your app.

References

34 Using Contextual Events, Oracle® Fusion Middleware Fusion Developer’s Guide for Oracle Application Development Framework 11g Release 2 (11.1.2.1.0)

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: