The below code shows how to programmatically navigate to next jsf page in taskflow. Mainly this is used for conditional navigation i.e., based on some logic we can dynamically decide which page needs to be shown to the user.
Code for navigate() method:
In the above code, 'submit' is the 'action' attribute based on which the next jsff page in the flow will be decided.
public void submitClicked(ActionEvent actionEvent) { navigate(actionEvent, "submit"); }
Code for navigate() method:
protected void navigate(FacesEvent event, String outcome) { RichRegion regionComponent = null; for (UIComponent uic = event.getComponent().getParent(); uic != null; uic = uic.getParent()) { if (uic instanceof RichRegion) { regionComponent = (RichRegion) uic; break; } } if (regionComponent != null) { FacesContext fc = FacesContext.getCurrentInstance(); ExpressionFactory ef = fc.getApplication().getExpressionFactory(); ELContext elc = fc.getELContext(); MethodExpression me = ef.createMethodExpression(elc, outcome, String.class, new Class[] { }); regionComponent .queueActionEventInRegion(me, null, null, false, -1, -1, event.getPhaseId()); } }

