Reinitialise taskFlow in dynamic region and set focus to default activity

Sharing is Caring

Hello All, In this post I’ll show how to reinitialise taskFlow in the dynamic region in an ADF Application.

We all use bounded task flows in ADF application development and to switch between multiple taskflows we use the concept of the dynamic region

Recently I came across a problem about the dynamic region and bounded task flows, Scenario is like this

I have dropped a BTF in the dynamic region and there is a link on the page to open that task flow and those who have used dynamic region would be familiar with this piece of code

 

 private String taskFlowId = "/WEB-INF/task-flow-definition.xml#task-flow-definition";

public TaskFlowId getDynamicTaskFlowId() {
return TaskFlowId.parse(taskFlowId);
}

public void setDynamicTaskFlowId(String taskFlowId) {
this.taskFlowId = taskFlowId;
}

//Method to open BTF
public String testDocTF() {
setDynamicTaskFlowId("/WEB-INF/TestDocTF.xml#TestDocTF");
return null;
}

and the important thing is that this BTF has two view activities (view1 and view2), view1 is default activity.

Reinitialise taskFlow

When the user clicks on the link it opens default activity in the dynamic region and then user navigate to second activity by clicking a button on default activity

Now user clicks the link again but this time page refreshed but default activity is not loaded, the dynamic region shows second activity (It is not expected as the requirement is to re-initialize task flow and load default activity again)
So to do that we need to refresh task flow (to Reinitialise taskflow) and for that just add one more line in the code, Bind region to bean and refresh it

 

   private RichRegion regionBind;

public void setRegionBind(RichRegion regionBind) {
this.regionBind = regionBind;
}

public RichRegion getRegionBind() {
return regionBind;
}

//Method to open BTF
public String testDocTF() {
//Refresh region and re-initialise taskFlow
regionBind.refresh(FacesContext.getCurrentInstance());

setDynamicTaskFlowId("/WEB-INF/TestDocTF.xml#TestDocTF");
return null;
}

Cheers 🙂 Happy Learning

Related Posts

Leave a Reply

Your email address will not be published. Required fields are marked *