Saturday, June 25, 2016

Contextual Event to pass value from Child Task flow to Parent Task flow

I've encountered an interesting problem where a child task flow is receiving parameters from parent pageFlowScope and needs to be refreshed from a sibling task flow.
This can't be achieved as the parameter is out of scope of the child task flow.

One way of solving this is by using SessionScope variable as parameter, but is not advisable.

Better solution is to use contextual event and page variables in conjunction:
A contextual event is created from Action (in my case a button click). Intended value is passed as payLoad along with this contextual event.

On the button component, a new contextual event can be published

 


Now we create a EventHandler class and write a method to take the parameter from the event.


Now the EventHandler class has to be exposed as Data Control.
And the handler method be added to binding of the consumer page.

In the parent page, we create the event mapping between publisher and subscriber.



Actual trick is to replace pageFlowScope parameter of child taskflow with a variable bound attribute on the page.

 Create a page level variable.
Though, initial value of variable is set to pageFlowScope value.





Create an attribute binding for this variable.

 This attribute from binding is used as input parameter to the taskflow.

And in the eventHandler, we get the published payload and set the page variable using a method in ADFUtils class.
               "ADFUtils.setBoundAttributeValue"

And the final step is to set the refresh property of taskflow binding to 'ifNeeded' so that region refreshes when one of the parameter is changed.

Now with a trigger from one of the child taskflows, contextual event is published and is captured on the parent page and refreshes a sibling child taskflow.