JSF 2 Implicit Navigation

 

In a JSF 2 application, the navigation rules are used to describe which view to render when a button or a link is clicked, they can be defined either in faces-config.xml or in managed beans.

We can also implement navigation without declaring any rule, by using implicit navigation (or auto navigation) .

In this example, we will see how to implement the implicit navigation in a JSF 2 application.

 

1. Technologies used

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

 

2. Project structure

JSF2-Implicit-Navigation

 

3. In JSF page

We have just to set the view name in the action attribute of the commandButton tag :

 

So, when the button is clicked, JSF 2 will add xhtml extension to the action attribute value (nextpage)  and search the nextpage.xhtml view in the current directory

 

4. In Managed Bean

We need to create a method that returns the view name :

 

And in the action attribute, we call our method using expression language :

 

5. Test It

URL : http://localhost:8080/JSF2-Implicit-Navigation/
JSF2-Implicit-Navigation-1

 We press the button :

JSF2-Implicit-Navigation-2

 

Download source code