Thursday, November 17, 2011

ADF Contextual Events

Oracle provides us with a very powerful feature to implement view-to-region, region-to-view, and region-to-region communication without requiring the region or the reference bounded task-flow to be refresh or restarted.

In this example, i will be showing you on how you can achieve region-to-region communication using the HR schema. I will create two task-flows, each consisting of a single JSF page fragment. The first JSF page fragment (named PageA.jsff) includes the employeess ADF form with some navigation controls and a submit button and the second JSF page fragment (names PageB.jsff) includes the employees ADF table.

I have created a third JSF page, demo.jspx, which will include the above stated pages as regions. I will use ADF Contextual Events to refresh the employees ADF table once a change has been made in an employee using the employee ADF form in the first page.

I have created a new application (named "ADFContextualEvents") with the "Fusion Web Application (ADF)" application template and using the "Business Components from Tables" i have created a connection to the HR schema, creating the Employees entity, a default view for the Employeess entity (EmployeesView) and an Application Module which includes the EmployeesView.

I created two task-flows, TaskFlowA and TaskFlowB. Both task-flows include a single JSF page fragment (TaskFlowA includes PageA and TaskFlowB includes PageB). The first page includes the Employees ADF Form
while the second page includes the employees ADF table.
I then created a normal jspx page (called demo.jspx) which includes the two task-flows created above as an ADF region. If you run the page and try to do a change in one of the employees, you will see that the changes are not reflected in the table below.
To refresh the view and subsequently the table to show the changes made in the form above, I will use Contextual Events. So the first thing that I will do is to create a method in the Application Module that will refresh (by re-executing) the view.
public void refreshEmployees(){
Please make sure that you expose this new method to the UI using the client interface option of the Application Module.
You need to add this method in PageB’s bindings as a method action using the page definition file.
Next, you need to define when the event should be triggered. This should be every time the user clicks the “Submit” button that is included in PageA (where the ADF Form is).
Finally, in the page that includes both task-flows as regions (demo.jspx), we need to define the subscriber for the event that will be triggered with the Submit button. To do so, go the page definition and select the “Contextual Events” and then the “Subscibers” tab and click on the green plus icon “Add a New Subscription”.
In the “Subscribe to Contextual Event” window, select the event that you have created, the publisher of the event and the handler (in our case, it is the method that we have created in the Application Module and included it in the second page’s page definition as a method action, and click OK.
If you run the demo page that includes both task-flows as regions, you will see that by doing a change in one of the employees using the employee form, the employees table displays the new changes without needing to refresh the region or page.
Download: ADF Contextual Events