Tuesday, December 1, 2009

Setting ADF view object bind variable programatically

Let's say you have an ADF VO defined which uses a Bind Variable, such as:

...and line.order_header_id = :paramOrderHeaderId

You want to set this parameter before the view is used, perhaps before a page is displayed which shows data from that view. There are a couple of ways to do this:


Option 1: Use a page invokeAction to call an AM method to set the bind variable. (RECOMMEND WAY)

Firstly create a method in your application module to set the view parameter, such as:


public void initializeMyVO() {
MyVOImpl vo = (MyVOImpl)findViewObject("MyVO1"); vo.setNamedWhereClauseParam("paramOrderHeaderId",new Long("100000013205391"));

}

Next in your application module definition expose this method on the client interface.

On the page which has a binding for your view, create a method action binding for this method such as:

<methodAction id="initializeMyVO" InstanceName="MyAppModuleDataControl.dataProvider" DataControl="MyAppModuleDataControl" RequiresUpdateModel="true" Action="invokeMethod" MethodName="initializeMyVO" IsViewObjectMethod="false"/>

Then create an invokeAction to call your AM method. This is done in the page definition file such as:

<invokeAction id="executeInitialize" Binds="initializeMyVO" Refresh="prepareModel" RefreshCondition="${!adfFacesContext.postback}"/>

The above refresh conditions should call this method only once when the page is shown. For more explanation on the refresh conditions see: http://download.oracle.com/docs/html/B25947_01/bcdcpal005.htm#sthref837



Option 2: Call AM method from a task flow

Optionally you can also create the same application module method as above, but call it from a task flow. Just drag and drop the method from your application module's data control to the task flow diagram. You can call the method before your page is invoked or as needed. If you have a bounded task flow, you could make this call the default activity.


Option 3: Retrieve the bind variable variable from user session data hash table



With this option you can have your bind variable use a Groovy expression to get the value of a variable that was placed in the user data hash table. This method is described in Manish Rungta's blog at: http://blog.us.oracle.com/manish/?96498842

No comments:

Post a Comment