Testcase:
I have a parent taskflow (say PTF) having a jsff page (say ParentPage) and you can navigate to two other pages Outcome1 and Outcome2 as shown below:
As you can see in the child taskflow (CTF) there are two return activities namely ReturnActivity1 and ReturnActivity2. Now lets go the solution.
As a first approach to the solution create a return taskflow parameter for the child taskflow (CTF) as shown and set the value to a pageFlowScope value.
Within the Child taskflow make sure the value of the pageFlowScope parameter is set to correct return activity before the taskflow return activity executes. This could be done either by method call activity return the taskflow return value and setting it to pageFlowScope.
Or by dropping setActionListener on the button/menu that leads to the return activity and set the pageFlowScope on it. On a bean create a method that would act as a finalizer for CTF to capture the value in a variable.
public String ReturnActivityValue = null;
public void finalizerForCTF(){
Map taskFlowReturnParameters = getCurrentTaskFlowReturnParameters();
ReturnActivityValue = getReturnActivityValue(taskFlowReturnParameters);
}
public static TaskFlowId getTaskFlowId() {
ControllerContext controllerContext = ControllerContext.getInstance();
ViewPortContext currentViewPort = controllerContext.getCurrentViewPort();
TaskFlowContext taskFlowContext = currentViewPort.getTaskFlowContext();
TaskFlowId taskFlowId = taskFlowContext.getTaskFlowId();
return taskFlowId;
}
public static Map getCurrentTaskFlowReturnParameters() {
return getReturnParameters(getTaskFlowId());
}
public static Map getReturnParameters(TaskFlowId taskFlowId) {
assert taskFlowId != null;
TaskFlowDefinition taskFlowDefinition = getTaskFlowDefinition(taskFlowId);
Map namedParameters = taskFlowDefinition.getReturnValues();
return namedParameters;
}
public static TaskFlowDefinition getTaskFlowDefinition(TaskFlowId taskFlowId) {
assert taskFlowId != null;
MetadataService metadataService = MetadataService.getInstance();
TaskFlowDefinition taskFlowDefinition = metadataService.getTaskFlowDefinition(taskFlowId);
return taskFlowDefinition;
}
public String getReturnActivityValue(Map btfParameters) {
HashMap taskFlowParameterValues = new HashMap();
FacesContext facesContext = FacesContext.getCurrentInstance();
Application application = facesContext.getApplication();
AdfFacesContext adfFacesContext = AdfFacesContext.getCurrentInstance();
Map pageFlowScope = adfFacesContext.getPageFlowScope();
String returnValue = null;
for (Object parameter : btfParameters.values()) {
NamedParameter namedParameter = (NamedParameter)parameter;
String parameterName = namedParameter.getName();
String parameterExpression = namedParameter.getValueExpression();
Object parameterValue;
String stringValue;
if (parameterExpression == null) {
parameterValue = pageFlowScope.get(parameterName);
} else {
parameterValue = application.evaluateExpressionGet(facesContext, parameterExpression, Object.class);
}
if (parameterValue != null) {
try {
stringValue = parameterValue.toString();
} catch (Exception e) {
stringValue = "
}
} else {
stringValue = "
}
if("ReturnActivityValue".equalsIgnoreCase(parameterName)){
returnValue = stringValue;
}
}
return returnValue;
}
Associate finalizerForCTF() with the CTF takflow as below:
private static final String Exit1Value = "RA1";
private static final String Exit2Value = "RA2";
public void regionNavationListener(RegionNavigationEvent regionNavigationEvent) {
if(regionNavigationEvent.getNewViewId() == null && ReturnActivityValue != null){
if(Exit1Value.equalsIgnoreCase(ReturnActivityValue)){
navigate("outcome1");
}else if(Exit2Value.equalsIgnoreCase(ReturnActivityValue)){
navigate("outcome2");
}
}
}
public void navigate(String controlFlowCase){
NavigationHandler nvHndlr =
FacesContext.getCurrentInstance().getApplication().getNavigationHandler();
nvHndlr .handleNavigation(FacesContext.getCurrentInstance(), null,
controlFlowCase);
}
Associate the method with region navigation listener.