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 thought on “XML-less JSF Navigation

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.