Tuesday, July 22, 2008

ADF navigation - (master detail)

When you want to navigate to Employees page from Departments list, say on click of a hyperlink of the department name, you should set the rowKey of the clicked Department, so that, when the detail view (Employees) is rendered, the correct row is picked up, and corresponding list of Employees is rendered.

You can achieve it in atleast three different ways :

1. Refer to my previous blog
http://nattu4u.blogspot.com/2008/07/
navigating-to-new-page-from-adf-table.html

2. In your ADF table (Departments), your commandLink should look like this :

af:commandLink text="#{row.PgmName}" action="empList"
actionListener="#{bindings.setCurrentRowWithKey.execute}"/>
In the corresponding pageDef,
action IterBinding="ProgramViewIterator" id="setCurrentRowWithKey"
InstanceName="CoreApplicationModuleDataControl.ProgramView"
DataControl="CoreApplicationModuleDataControl"
RequiresUpdateModel="false" Action="96">
NamedData NDName="rowKey" NDValue="#{row.rowKeyStr}"
NDType="java.lang.String"/>
/action

Thats all, and you are set to visit correct set of associated employees, when you click on hyperlink of DeptName.

3. The problem I foresee with the 2nd approach is, suppose, the value rowKeyStr might be lost in transit while you are navigating from Departments to the Employees page. A fool proof method would be to make use of "processScope" object, to set and retrieve the rowKey.

You can do so like this:

In Dept page, for the commandLink:

af:setActionListener to="#{processScope.deptKey}"
from="#{row.rowKeyStr}"/>
In Emp PageDef

Under executables:

invokeAction id="setCurrentRowFromProgramId" Binds="setCurrentRowWithKey"
RefreshCondition="${adfFacesContext.postback==false}">

Under bindings

action IterBinding="DeptViewIterator" id="setCurrentRowWithKey"
InstanceName="CoreApplicationModuleDataControl.DeptView"
DataControl="CoreApplicationModuleDataControl"
RequiresUpdateModel="false" Action="96">
NamedData NDName="rowKey" NDValue="#{processScope.deptKey}"
NDType="java.lang.String"/>
/action>

So, you are setting the deptKey when you click on department name, and you are retrieving when you execute the setCurrentRowWithKey action. This would get executed, when you navigate to the Employees page and the invokeAction gets executed during the page launch.

So, you are setting it before and getting it when you launch this page. Logical rite ?

No comments: