Daily Archives: November 18, 2013

Java Server Faces Page Navigation Rule

Java Server Faces Page Navigation Rule

A navigation rule in a faces-config.xml file.In our application, we create the pages directory that includes: index.jsp, Mirek.jsp, and Bolek.jsp. So the directory tree look in the following way:





The index.jsp file is default: when we start our web application it will be displayed without our action. However, our application can have more web pages to display. If we need to navigate to other page, just use this way:

<?xml version=’1.0′ encoding=’UTF-8′?>
<faces-config version=”2.2″
    xsi:schemaLocation=”http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-facesconfig_2_2.xsd”&gt;
















We define a navigation rules in Java Server Faces between <navigation-rule> and </navigation-rule>.

We have three pages: index.jsp, Mirek.jsp, and Bolek.jsp. To navigate from index.jsp to Mirek.jsp, we use the first snippet between <navigation-case></navigation-case>. To navigate from index.jsp to Bolek.jso, we use the second snipped between <navigation-case></navigation-case>.

<redirect/> – it helps to redirect to other page, so better do not forget this tag; after redirecting you see only the content of the redirected page, not the one of the redirected page and the one of the first page, because forward dispatching is default. In other words, redirecting between two pages is going smoothly with this tag

<from-outcome></from-outcome> – the name between these tags you can use for redirecting; it represent the page, for example:

<h:commandButton … action=”mirek” > – w use mirek as a reference to the Mirek.jsp page on other page

<from-view-id></from-view-id> – the page we go from to other page

<to-view-id></to-view-id> – the page we go to from other page