JSF 2 Navigation Rules Example


In this example, we will see how to define navigation rules using the faces-config file and annotations.

We will implement the following navigation rules :

Access to the index page :

JSF 2 Implicit Navigation 1

If the name value is different from ‘walid‘, then go to error page :

JSF 2 Implicit Navigation 2

Else if the name value  is ‘walid‘, then go to admin page :

JSF 2 Implicit Navigation 3


1. Technologies used

  • JSF 2.2.8
  • Maven 3.0.5
  • Eclipse 4.4
  • JDK 1.7
  • Tomcat 7.0


2. Project structure

JSF 2 Implicit Navigation


To define our navigation rules, we can either use faces-config file or annotations


3. Using faces-config.xml file

File : index.xhtml




File : faces-config.xml


That means :



4. Using Managed Bean

File : index.xhtml




So submitting the index page will lunch the connect method which will return the view name to identify the destination of the navigation case, based on the name value.


Download source code