Let's say we have a page with a region and some bounded task flow inside the region. The task flow has some backingBean scope managed bean:
<managed-bean id="__1"> <managed-bean-name id="__2">BackBean</managed-bean-name> <managed-bean-class id="__3">view.BackBean</managed-bean-class> <managed-bean-scope id="__4">backingBean</managed-bean-scope> </managed-bean>
We need to have an access to this bean outside of the task flow. For example we need to disable a button on the main page depending on some property of the BackBean. We can do the following:
// taskflow is <taskFlow id="taskflowdefinition1" from our pageDef public Map getBackingBeanScope4TaskFlow(String taskflow) { Map resultMap = null; //We need the full name of our taskflow DCBindingContainer dcb = (DCBindingContainer)BindingContext.getCurrent().getCurrentBindingsEntry(); DCTaskFlowBinding dfb = (DCTaskFlowBinding) dcb.findExecutableBinding(taskflow); String fullName = dfb.getFullName(); //Get the provider BackingBeanScopeProviderImpl bbProvider = ((BackingBeanScopeProviderImpl)AdfFacesContext.getCurrentInstance().getBackingBeanScopeProvider()); //Left parenthesis bbProvider.begin(fullName); //Now the current backing bean scope is the scope of our task flow try { resultMap = bbProvider.getCurrentScope(); } finally { //Right parenthesis bbProvider.end(); } return resultMap; } public Object getBackBean() { return getBackingBeanScope4TaskFlow("taskflowdefinition1").get("BackBean"); }
Of-course using this technique is a little bit against the encapsulation concept - we should not have access to the details of the inner/child objects. We have to be aware of that. And for our use-case it'd be probably better to use contextual events or something else. But in any case we know how to do the trick, and Knowledge is Power :).
That's it!
No comments:
Post a Comment
Post Comment