Building a custom event dispatcher for Contextual Events

ADF lets you to create custom event dispatcher to override the default one to provide custom behaviors. In this post, I'm sharing a simple example built using a custom event dispatcher. Please refer this topic 28.7.6 How to Register a Custom Event Dispatcher in Fusion Developer's Guide to learn more about this topic.

A glance at the implementation

1. You can create your own event dispatcher (from scratch) by implementing oracle.adf.model.events.EventDispatcher. Alternatively, if you want to override specific behavior alone then consider sub classing oracle.adf.model.binding.events.EventDispatcherImpl or its base class - AbstractEventDispatcher.

2. Next step is to register the custom event dispatcher in the Databindings.cpx file
<?xml version="1.0" encoding="UTF-8" ?>
<Application xmlns="http://xmlns.oracle.com/adfm/application"
  version="11.1.1.56.60" id="DataBindings" SeparateXMLFiles="false"
  Package="view" ClientType="Generic"
  EventDispatcher="view.extension.CustomEventDispatcherImpl">

Cool...The basic infrastructure to use your custom event dispatcher is in place now. enjoy !

You can download the sample workspace from here.
[Runs with Oracle JDeveloper 11g R1 PS2 + HR Schema]

How to run this sample?

This sample is configured to use view.extension.CustomEventDispatcherImpl class as event dispatcher. The CustomEventDispatcherImpl class check for the event payload type and if payload is 'instance of' view.extension.OriginAwarePayLoad, then decorates the payload by adding the producer name. Please note that, this is just a simple example to illustrate the custom event dispatcher. You can have more smart implementations (based on your use cases) and do it in your own way!

1. Run the main.jspx
2. Click on the Command Button which generates contextual event. Here the event payload is defined as a custom object, sub classed from a view.extension.OriginAwarePayLoad.
3. Control comes to the custom event dispatcher - CustomEventDispatcherImpl . This class overrides invokeEvent(...) to add 'event producer id' to the pay load.
4. Finally, event handler method (defined for the subscriber) receives this decorated payload and the same is used for further execution.

Comments

Disclaimer

The views expressed on this blog are my own and do not necessarily reflect the views of my employer.