Tuesday, January 15, 2013

Fragment Template to Fragment Communication with ADF Contextual Events

This post is extended version for my previous post - After Commit Call for Centralized Transaction Management. Previously posted application works as it should, but you may face a bit more complex use case when fragment template will be assigned with page definition file. If there will be page definition file for the fragment template - it will not work to call method by managed bean reference and invoke operation from fragment page definition. The thing is - page definition context will be changed from fragment to fragment template and operations declared in the fragment page definition will be unaccessible. However, we can implement communication between fragment template and fragment itself through ADF Contextual Events functionality.

Here is sample application with ADF Contextual Events enabled - GlobalTransactionControlApp_v3.zip. This sample implements generic communication solution based on contextual events. Global commit/rollback actions are handled from the fragment template, after commit we want to invoke refresh for the iterators declared in our fragment page definition. Each fragment in the application, is designed to pass iterator names through page template tag (we are going to use these names in generic method):


Multiple iterator names can be passed with dash separator:


Global method for commit operation in fragment template is reading template parameter value with iterator names and invoking contextual event to notify subscribers to invoke generic after commit method:


Contextual event is defined to send iterator names using payload parameter. I personally prefer to define contextual event code manually in the source code:


Contextual event subscriber method is reading payload value with iterator names to be refreshed and re-executing each of them in the loop:


You must generate data control on top of contextual event subscriber - this is needed to be able to register it in the same page definition file where our iterators are defined:


Once data control will be generated, we can add contextual event subscriber method to the fragment page definition file (same where we have iterators). Provide value payLoad for the method parameter, this is system keyword, it will pass through payload variable value from incoming contextual event:


Contextual event subscriber was defined manually in the source code:


Department - Employee fragment is defined to pass both iterator names to be refreshed after commit:


We can see that from the log - SQL is executed for Departments and Employees:


Employee fragment is passing only one iterator to be refreshed:


We can see that from the log - contextual event is triggering only one iterator refresh in the context of currently opened fragment:

No comments: