Friday, 21 February 2014

ADF Taskflow conditional activation

Sometimes is quite useful to make sure the taskflow is actually executed under a particular condition. Think about a panelTabbed component with 2 showDetailItem children, each of which consumes a taskflow inside a region:

<af:panelTabbed dimensionsFrom="auto" id="panelTabbed">
 <af:showDetailItem id="sdi2" text="First tab">
    <af:region id="r1" value="#{bindings.customTF1.regionModel}"/>
    <af:setPropertyListener from="TAB1" to="#{pageFlowScope.tabClicked}" 
                               type="disclosure"/>
 </af:showDetailItem>
 <af:showDetailItem id="sdi1" text="Second tab">
  <af:region id="r2" value="#{bindings.customTF2.regionModel}"/>
  <af:setPropertyListener from="TAB2" to="#{pageFlowScope.tabClicked}" 
                             type="disclosure"/>            
 </af:showDetailItem>
</af:panelTabbed>
By default, when this component is rendered, both taskflows are executed, whether they are in the disclosed showDetailItem or not.

Since the execution of a taskflow may imply a significant overhead for our application, we may decide that the taskflow needs to be executed only when the tab containing it is actually disclosed.

For this purpose, we can set the the activation propery of the taskflow binding to 'conditional', instead of 'deferred' (default). In order to do that, we need to provide a condition for the taskflow to be activated: for this purpose we can use a setPropertyListener operation inside each showDetailItem component to set a property called 'tabClicked' in the pageFlowScope, the value we set obviously is different for every tab. This property will be used in the EL expression to check the taskflow activation condition.
In the page bindings where the panelTabbed (and the regions) are used, make sure to setup the taskflow bindings attributes as described before:

<taskflow activation="conditional" active="#{pageFlowScope.tabClicked=='TAB1'}" 
          id="customTF1" 
          taskflowid="/WEB-INF/taskflows/ws/customTF1.xml#customTF1" 
          xmlns="http://xmlns.oracle.com/adf/controller/binding">
  <parameters>
 [...]
  </parameters>
</taskflow>
<taskflow activation="deferred" active="#{pageFlowScope.tabClicked=='TAB2'}" 
          id="customTF2" 
          taskflowid="/WEB-INF/taskflows/ws/customTF2.xml#customTF2" 
          xmlns="http://xmlns.oracle.com/adf/controller/binding">
  <parameters>
 [...]
  </parameters>
</taskflow>


At this point, the taskflows should be invoked only when they are actually shown on the page (i.e. when the tab containing it is disclosed).

No comments:

Post a Comment