Document Information


Part I Introduction

1.  Overview

2.  Using the Tutorial Examples

Part II The Web Tier

3.  Getting Started with Web Applications

4.  JavaServer Faces Technology

5.  Introduction to Facelets

6.  Expression Language

7.  Using JavaServer Faces Technology in Web Pages

8.  Using Converters, Listeners, and Validators

9.  Developing with JavaServer Faces Technology

10.  JavaServer Faces Technology: Advanced Concepts

11.  Using Ajax with JavaServer Faces Technology

12.  Composite Components: Advanced Topics and Example

13.  Creating Custom UI Components and Other Custom Objects

14.  Configuring JavaServer Faces Applications

Using Annotations to Configure Managed Beans

Using Managed Bean Scopes

Eager Application-Scoped Beans

Application Configuration Resource File

Ordering of Application Configuration Resource Files

Configuring Managed Beans

Using the managed-bean Element

Initializing Properties Using the managed-property Element

Referencing a Java Enum Type

Referencing a Context Initialization Parameter

Initializing Map Properties

Initializing Array and List Properties

Initializing Managed Bean Properties

Initializing Maps and Lists

Registering Application Messages

Using FacesMessage to Create a Message

Referencing Error Messages

Using Default Validators

Registering a Custom Validator

Registering a Custom Converter

Registering a Custom Renderer with a Render Kit

Registering a Custom Component

Basic Requirements of a JavaServer Faces Application

Configuring an Application with a Web Deployment Descriptor

Identifying the Servlet for Lifecycle Processing

To Specify a Path to an Application Configuration Resource File

To Specify Where State Is Saved

Configuring Project Stage

Including the Classes, Pages, and Other Resources

15.  Java Servlet Technology

16.  Uploading Files with Java Servlet Technology

17.  Internationalizing and Localizing Web Applications

Part III Web Services

18.  Introduction to Web Services

19.  Building Web Services with JAX-WS

20.  Building RESTful Web Services with JAX-RS

21.  JAX-RS: Advanced Topics and Example

Part IV Enterprise Beans

22.  Enterprise Beans

23.  Getting Started with Enterprise Beans

24.  Running the Enterprise Bean Examples

25.  A Message-Driven Bean Example

26.  Using the Embedded Enterprise Bean Container

27.  Using Asynchronous Method Invocation in Session Beans

Part V Contexts and Dependency Injection for the Java EE Platform

28.  Introduction to Contexts and Dependency Injection for the Java EE Platform

29.  Running the Basic Contexts and Dependency Injection Examples

30.  Contexts and Dependency Injection for the Java EE Platform: Advanced Topics

31.  Running the Advanced Contexts and Dependency Injection Examples

Part VI Persistence

32.  Introduction to the Java Persistence API

33.  Running the Persistence Examples

34.  The Java Persistence Query Language

35.  Using the Criteria API to Create Queries

36.  Creating and Using String-Based Criteria Queries

37.  Controlling Concurrent Access to Entity Data with Locking

38.  Using a Second-Level Cache with Java Persistence API Applications

Part VII Security

39.  Introduction to Security in the Java EE Platform

40.  Getting Started Securing Web Applications

41.  Getting Started Securing Enterprise Applications

42.  Java EE Security: Advanced Topics

Part VIII Java EE Supporting Technologies

43.  Introduction to Java EE Supporting Technologies

44.  Transactions

45.  Resources and Resource Adapters

46.  The Resource Adapter Example

47.  Java Message Service Concepts

48.  Java Message Service Examples

49.  Bean Validation: Advanced Topics

50.  Using Java EE Interceptors

Part IX Case Studies

51.  Duke's Bookstore Case Study Example

52.  Duke's Tutoring Case Study Example

53.  Duke's Forest Case Study Example



Configuring Navigation Rules

Navigation between different pages of a JavaServer Faces application, such as choosing the next page to be displayed after a button or hyperlink 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 Implicit Navigation Rules.

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 action method invoked when the component was clicked

  • The logical outcome referenced by the component’s tag or returned from the action method

The outcome can be anything the developer chooses, but Table 14-3 lists some outcomes commonly used in web applications.

Table 14-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.

no results

The search did not find anything. Go to the search page again.

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 success. 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 described:


This navigation rule defines the possible ways to navigate from login.xhtml. Each navigation-case element defines one possible navigation path from login.xhtml. The first navigation-case says that if LoginForm.login returns an outcome of success, then storefront.xhtml will be accessed. The second navigation-case says that login.xhtml will be re-rendered if LoginForm.login returns failure.

The configuration of an application’s page flow consists of a set of navigation rules. Each rule is defined by the navigation-rule element in the faces-config.xml file.

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:


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.

The navigation-case elements are checked against the outcome and the method expression in this order:

  1. Cases specifying both a from-outcome value and a from-action value. Both of these elements can be used if the action method returns different outcomes depending on the result of the processing it performs.

  2. Cases specifying only a from-outcome value. The from-outcome element must match either the outcome defined by the action attribute of the javax.faces.component.UICommand component or the outcome returned by the method referred to by the UICommand component.

  3. Cases specifying only a from-action value. This value must match the 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.

To Configure a Navigation Rule

Using NetBeans IDE, you can configure a navigation rule by doing the following.

  1. After opening your project in NetBeans IDE, expand the project node in the Projects pane.
  2. Expand the Web Pages and WEB-INF nodes of the project node.
  3. Double-click faces-config.xml.
  4. After faces-config.xml opens in the editor pane, right-click in the editor pane.
  5. From the Insert menu, choose Navigation Rule.
  6. In the Add Navigation Rule dialog:
    1. Enter or browse for the page that represents the starting view for this navigation rule.
    2. Click Add.
  7. Right-click again in the editor pane.
  8. From the Insert menu, choose Navigation Case.
  9. In the Add Navigation Case dialog box:
    1. From the From View menu, choose the page that represents the starting view for the navigation rule (from Step 6 a).
    2. (optional) In the From Action field, type the action method invoked when the component that triggered navigation is activated.
    3. (optional) In the From Outcome field, enter the logical outcome string that the activated component references from its action attribute.
    4. From the To View menu, choose or browse for the page that will be opened if this navigation case is selected by the navigation system.
    5. Click Add.

See Also

Referencing a Method That Performs Navigation explains how to use a component tag’s action attribute to point to an action method. Writing a Method to Handle Navigation explains how to write an action method.

Implicit Navigation Rules

JavaServer Faces technology supports implicit navigation rules for Facelets applications. Implicit navigation applies when navigation-rules are not configured in the application configuration resource files.

When you add a component such as a commandButton in a page, and assign another page as the value for its action property, the default navigation handler will try to match a suitable page within the application implicitly.

<h:commandButton value="submit" action="response">

In the above example, the default navigation handler will try to locate a page named response.xhtml within the application and navigate to it.