Friday, May 9, 2014

Parent to Region Communication using Shared & Isolated DataControls

In this post we will look at how Parent and Region communications are done in ADF. We will take two cases in this post. One is when by default Task Flows are set to have Shared Data Control scope and the other one is when Task Flows are set to use Isolated Data Control Scope.

Below is the picture which depicts what we are targeting to achieve.

We have a page which has two buttons. Next and Previous. These buttons are from DepartmentsVO which will move to the next and previous row of department table. Inside the page, there is a Employees Task Flow which is added as a Region.

The communication use case is , that when next and previous buttons on the page are clicked, the list of employees inside the EmployeesTaskFlow should change accordingly. Employees shown should be in a particular department which is being pointed by the buttons in iterator.

So lets get our hands on and start developing the use case.

Created a simple ADF Project with Model and ViewController. Created ADF BC out of HR schema for Employees and Departments table.

We have two use cases. First one is for Shared Data Control and Second one is for Isolated Data Control :

TaskFlow with Shared Data Control

Created a task flow parent-region-case1 having one View default activity.

In the jsff, created a ADF Table using EmployeesVo which is has a master Vo as DepartmentsVO.

Now created one jspx - ParentPageCase1.jspx where added Next and Previous operations of DepartmentsVO which is master of EmployeesVO which we dragged in the Jsff.

We also dragged the task flow in ParentPageCase1.jspx as a region.

Run the jspx and you will see that when one scrolls to next department , region is refreshed to show employees present in that department.

Now lets do one thing. Lets change the data control scope of Task Flow to Isolated.

Now if we run the page and click on the next button, the region will not refresh and will not show the employees for the department we clicked next for. 

For this case we need to have another approach which is described next.

TaskFlow with Shared Data Control

Since we saw that using above implementation, task flow with Isolated Data Control won't work, we need to have different approach. 

For this create another view object EmployeesVOForIsolatedDC out of EmployeeVO having a view criteria for DepartmentId.

Add EmployeesVOForIsolatedDC in the AM Data Model and add view criteria to it.

Created a new task flow parent-region-isolateddc having first activity as executeWithParams having parameters as #{pageFlowScope.deptId} for deptId.

It has two view activities. One is regionToParentIsolatedDC.jsff which just shows the AF Table out of EmployeesVOForIsolatedDC VO.

The other activity is just a next jsff which previous fragment can navigate to. It just has an output text.

If we see this task flow accepts parameter which is nothing but department id.

Lastly lets create as jspx ParentToRegionIsolated.jspx and drag this task flow and provide the input parameter value.

ParentToRegionIsolated binding looks like below. Created attribute value for DepartmentId for using it.

Now lets run the page.

You will see we were able to navigate to next departments and employees in the region were refreshed to that department.

There is one more button next at bottom which takes you to next View Activity which has just output text.

Now on the next fragement and on click of Next button in the parent page, again first page is shown. Important :- This is because, Whenever anything in parent page is changed , it will Re Instantiate the task flow and will refresh the region.

This means if user is in middle of any transaction and parent page navigation is pressed, all of its data will be lost and user will be greeted with the default activity in the task flow.

 When clicked on Next (Which is on parent page) below is the first screen of task flow.

If we want that task flow should not be restarted /  Re Instantiate , there are different approaches which should be followed.

Future posts will be on how to achieve this.

Stay Tuned !!


No comments:

Post a Comment