XML-less JSF Navigation

Cagatay Civici posted a very neat example of using JSF navigation without XML (without defining navigation rules in JSF configuration file). I simplified the custom navigation handler even further. It is safe to assume that most people today use Facelets (I do in all my projects and trainings, plus it’s going to be used in JSF 2.0), so we don’t have to check the javax.faces.DEFAULT_SUFFIX context param. So, instead of using:

public String navigate () {
  return "somepage"
}

it’s now possible to use this:

public String navigate () {
  return "/somepage.xhtml"
}

or even like this if there is no action:


getTargetViewId method now looks like this:

private String getTargetViewId(FacesContext facesContext, String outcome) {
   String targetViewId;

   if (isRedirect(outcome)){
      targetViewId = outcome.split(":")[1];
   } else {
      targetViewId = outcome;
   }
}

Thanks Cagatay for posting this!

One response to “XML-less JSF Navigation”

  1. […] setting action=”page.xhtml” because I’m using a custom navigation handler. Standard navigation rules will work the same […]

Leave a comment