Saturday, October 30, 2010

ADF UI - Navigating to next jsf page programmatically (instead of specifying 'action' declaratively)

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.

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()); } }
In the above code, 'submit' is the 'action' attribute based on which the next jsff page in the flow will be decided.


  1. Why don't you use a method call activity or (even better) a router) if it is all about directing different users to different views? The approach of using HandleNavigation is not optimal

  2. I agree with Frank. If we think about our problem, most of the time we can resolve it by method call activity or router.

  3. thanks for the post! lot of the flow in my application is happening programmatically. This post helps there.

  4. We have an updated tutorial covering this along with a step-by-step tutorial video at this link -


Related Posts with Thumbnails