Pages

Thursday, January 20, 2011

Get the PageFlowScope of a Region Bounded Task Flow

Sometimes you need to access the PageFlowScope of a Task Flow Region( child Bounded Task Flow ) and get a handle to a pageFlowScope managed Bean. Normally you don't need to do this and Oracle don't want you, to do this. To make this work you need three internal classes so there is no guarantee that it works in 11g R1 PS4 or higher, but it work in PS2 & PS3.

Basically this is what you need to do.

  • Get the Task Flow binding of the region in the page definition, you need to have the full name
  • Get the RootViewPortContext
  • Find the ChildViewPortContext , use the TaskFlow full name
  • Get the pageFlowScope Map of the ChildViewPortContext 

Here some demo code.

package test.adf.global.beans;
import javax.faces.event.ActionEvent;
import java.util.Map;
import oracle.adf.controller.ControllerContext;
import oracle.adf.model.BindingContext;
import oracle.adf.model.binding.DCBindingContainer;
import oracle.adf.view.rich.context.AdfFacesContext;
import oracle.adf.controller.internal.binding.DCTaskFlowBinding;
import oracle.adfinternal.controller.state.ChildViewPortContextImpl;
import oracle.adfinternal.controller.state.RootViewPortContextImpl;
import test.adf.global.interfaces.BeanInt;
public class MainBean {
public MainBean() {
}
private String name = "main";
public void setName(String name) {
this.name = name;
}
public String getName() {
return name;
}
// dump current Task Flow pageFlowScope
public void dumpPageFlowScope(ActionEvent actionEvent) {
AdfFacesContext facesCtx= null;
facesCtx= AdfFacesContext.getCurrentInstance();
Map<String, Object> scopeVar= facesCtx.getPageFlowScope();
for ( String key : scopeVar.keySet() ) {
System.out.println("key: "+key);
System.out.println("value: "+scopeVar.get(key));
}
}
// dump the child Task Flow pageFlowScope
public void dumpChildPageFlowScope(ActionEvent actionEvent) {
// get the current BindingContainer
BindingContext bctx = BindingContext.getCurrent();
DCBindingContainer mainViewPageBinding = (DCBindingContainer)
bctx.getCurrentBindingsEntry();
// find the task flow pagedef binding, see the pageDef
DCTaskFlowBinding tf = (DCTaskFlowBinding)
mainViewPageBinding.findExecutableBinding("child1");
System.out.println(tf.getFullName());
ControllerContext conn = ControllerContext.getInstance();
RootViewPortContextImpl rootViewPort =
(RootViewPortContextImpl) conn.getCurrentRootViewPort();
ChildViewPortContextImpl childView = (ChildViewPortContextImpl)
rootViewPort.getChildViewPortByClientId(tf.getFullName());
// get pageFlowScope
Map<String, Object> scopeVar= childView.getPageFlowScopeMap();
for ( String key : scopeVar.keySet() ) {
System.out.println("key: "+key);
System.out.println("value: "+scopeVar.get(key));
}
BeanInt bean = (BeanInt)scopeVar.get("childBean");
System.out.println(bean.getName());
}
}
view raw MainBean.java hosted with ❤ by GitHub
Here you can download the demo workspace

3 comments:

  1. Hi Biemond,

    Thank you for the post here!!!

    How do we use this without adfinternal package usage? as internal package/classes are meant for Oracle internal which may change without any notification.

    Please suggest if any alternate solution for the same.

    Thanks in advance!
    Shiavji

    ReplyDelete
    Replies
    1. Hi,

      sorry, Oracle don't want you to use it even when there is a valid use case, like in global menu and want to do things in a task flow fragment.
      But in 11gR1 there are not that many changes so it will always work in 11gR1


      thanks

      Delete