O'Reilly logo

JavaServer Faces by Hans Bergsten

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Chapter 9. Controlling Navigation

In this book's sample application, all main functionality is handled through a single screen, but that's not always the case, of course. Moving between screens in a web application based on user actions is a common requirement. In this chapter, we look at how JSF supports moving between screens implemented as JSF views as well as moving to screens implemented with other web page technology, such as pure HTML pages, or responses generated by regular servlets or a plain JSP pages without JSF components.

Moving Between JSF Views

In addition to the main functionality, the sample application lets the user edit preferences through a separate set of screens. The application ignores all preference settings, but looking at how these preferences screens are implemented illustrates how JSF navigation works.

On a regular web site, links are used to navigate between different pages. A JSF web application may also use links, and there's a special action element that you should use to add a link to a page. It's the <h:outputLink> action element, and here's how it's used in the sample application's menu area:

...
  <h:outputLink value="prefUser.faces">
    <h:outputText value="Preferences" />
  </h:outputLink>
...

The action uses the value attribute to render the corresponding HTML <a> element's href value, with an encoded session ID if needed for cookie-less session tracking. Nested <f:param> action elements can be used to add query string parameters (see Appendix A for details). ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required