FROM THE BLOG

ADF Tutorial: Contextual events, method in bean, no POJO DC for that please!

If you are familiar with ADF Contextual Events, then you will know that the events only happen in the Binding Layer, meaning that producers and consumers ought to be registered in some pageDef inside your ADF Application. Right, but what do you do when your consumer method is in your bean? You need to expose the method to your binding layer for it to be able to become a valid candidate to ‘consume’ any of your contextual event. You might be tempted to just create a POJO DC based on this bean just to be able to create a method binding in your pageDef only for this purpose or use a dummy method in your AppModule to do the job.

Steve Muench in his undocumented example 164 briefly explains a good general solution about how to call use a bean method in your bindings without having to expose it as a POJO DC. In this post, I will illustrate how to take advance of such feature when working with Taskflows Communication using contextual events. In the sample application, we’ve got two tasklfows. One containing the employees table (TF1) and another one to update an employee (TF2). Both taskflows are to be rendered as a region in a home page. We want to display a feedback message in TF1 as soon as a transaction is Commited in TF2 (employee has been updated).

This is the structure of the application:

adf_contextual_events_bindings_method_1

Below is the empTable region. As you can see, I am using a decorative panel where in the top facets, I placed a message with property rendered -> false and binded it to the taskflow backing bean.

adf_contextual_events_bindings_method_2

 

Below the backing bean:

adf_contextual_events_bindings_method_3

Now, in order to TF2 be able to communicate TF1 that a commit has been performed, we need to raise a new contextual event in the Commit operation of our TF2 region pageDef;

adf_contextual_events_bindings_method_6

As I stated before, contextual event only live in the binding layer, so in order to make our backing bean method able for events consuption, we need to expose it to the bindings. Many developer would be tempted to create a dummy POJO DC to get the method exposed in the DC or even in the AppModuleImpl. Although that approach would work, below is a better and cleaner approach that perhaps you did not know about;

You need to go to your page definition and write the following statement via source (using the UI you won’t be able to achieve it):

<methodAction DataControl=”AppModuleDataControl” — Your ApplicationModule name.
id=”CallMethodOnEmployeeTableBean” — Can be whatever you like.
InstanceName=”${EmpTableBean}” — Always use the $ sign and this must match the name                                                                                               — registered in your taskflow definition
MethodName=”showMessage“>         — Method on your bean.
<NamedData NDName=”payLoad” NDType=”java.lang.String”/>  — Parameter name of your                                                                                                                                                        — bean’s method
</methodAction>

adf_contextual_events_bindings_method_11

After this is done, you can carry on setting up contextual event as usual. In the home pageDef we go to contextual events and in the subscriber tab we click new and select our event ;

adf_contextual_events_bindings_method_8

We then can see our consumer method (because it has been exposed to our binding layer);

adf_contextual_events_bindings_method_9

And also specify the payLoad;

adf_contextual_events_bindings_method_10

Done!. When we run the page we see the following behavior – Select an employee and update any field;

adf_contextual_events_bindings_method_12

Click on commit – Events are raised and consumed. In this case our bean method is called to replace the _ char with the payLoad (EmployeeId) and update the rendered attribute to true and finally partialTargeting the message container;

adf_contextual_events_bindings_method_13

Leave a comment

Your email address will not be published.

Social Media

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