Navigation between different pages of a JavaServer Faces application,
such as choosing the next page to be displayed after a button or link
component is clicked, is defined by a set of rules. Navigation rules can
be implicit, or they can be explicitly defined in the application
configuration resource file. For more information on implicit navigation
rules, see Navigation Model.
Each navigation rule specifies how to navigate from one page to another
page or set of pages. The JavaServer Faces implementation chooses the
proper navigation rule according to which page is currently displayed.
After the proper navigation rule is selected, the choice of which page
to access next from the current page depends on two factors:
The outcome can be anything the developer chooses, but Table
16-3 lists some outcomes commonly used in web applications.
Table 16-3 Common Outcome Strings
What It Means
Everything worked. Go on to the next page.
Something is wrong. Go on to an error page.
The user needs to log in first. Go on to the login page.
The search did not find anything. Go to the search page
Usually, the action method performs some processing on the form data of
the current page. For example, the method might check whether the user
name and password entered in the form match the user name and password
on file. If they match, the method returns the outcome
Otherwise, it returns the outcome
failure. As this example
demonstrates, both the method used to process the action and the outcome
returned are necessary to determine the correct page to access.
Here is a navigation rule that could be used with the example just
This navigation rule defines the possible ways to navigate from
navigation-case element defines one possible
navigation path from
login.xhtml. The first
LoginForm.login returns an outcome of
storefront.xhtml will be accessed. The second
login.xhtml will be re-rendered if
The configuration of an application’s page flow consists of a set of
navigation rules. Each rule is defined by the
navigation-rule element corresponds to one component tree
identifier defined by the optional
from-view-id element. This means
that each rule defines all the possible ways to navigate from one
particular page in the application. If there is no
element, the navigation rules defined in the
apply to all the pages in the application. The
also allows wildcard matching patterns. For example, this
element says that the navigation rule applies to all the pages in the
navigation-rule element can contain zero or more
navigation-case element defines a set of matching
criteria. When these criteria are satisfied, the application will
navigate to the page defined by the
to-view-id element contained in
The navigation criteria are defined by optional
from-action elements. The
from-outcome element defines a logical
outcome, such as
from-action element uses a method
expression to refer to an action method that returns a
is the logical outcome. The method performs some logic to determine the
outcome and returns the outcome.
navigation-case elements are checked against the outcome and the
method expression in the following order.
Cases specifying both a
from-outcome value and a
value. Both of these elements can be used if the action method returns
different outcomes depending on the result of the processing it
Cases specifying only a
from-outcome value. The
element must match either the outcome defined by the
javax.faces.component.UICommand component or the outcome
returned by the method referred to by the
Cases specifying only a
from-action value. This value must match
action expression specified by the component tag.
When any of these cases is matched, the component tree defined by the
to-view-id element will be selected for rendering.