background image

The navigation-rule Element

<< Common Outcome Strings | The navigation-case Element >>
<< Common Outcome Strings | The navigation-case Element >>

The navigation-rule Element

<navigation-rule>
<from-view-id>/catalog.jsp</from-view-id>
<navigation-case>
<from-outcome>success</from-outcome>
<to-view-id>/bookcashier.jsp</to-view-id>
</navigation-case>
<navigation-case>
<from-outcome>out of stock</from-outcome>
<from-action>
#{catalog.buy}
</from-action>
<to-view-id>/outofstock.jsp</to-view-id>
</navigation-case>
<navigation-case>
<from-outcome>error</from-outcome>
<to-view-id>/error.jsp</to-view-id>
</navigation-case>
</navigation-rule>
The first navigation rule in this example says that the application will navigate from
catalog.jsp
to
bookcashier.jsp
if the item ordered is in stock
outofstock.jsp
if the item is out of stock
The second navigation rule says that the application will navigate from any page to error.jsp if
the application encountered an error.
Each 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 from-view-id element, the
navigation rules defined in the navigation-rule element apply to all the pages in the
application. The from-view-id element also allows wildcard matching patterns. For example,
this from-view-id element says that the navigation rule applies to all the pages in the books
directory:
<from-view-id>/books/*</from-view-id>
As shown in the example navigation rule, a navigation-rule element can contain zero or more
navigation-case
elements. The 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 same navigation-case element.
The navigation criteria are defined by optional from-outcome and from-action elements. The
from-outcome
element defines a logical outcome, such as success. The from-action element
uses a method expression to refer to an action method that returns a String, which is the logical
outcome. The method performs some logic to determine the outcome and returns the outcome.
Configuring Navigation Rules
Chapter 14 · Configuring JavaServer Faces Applications
453