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.
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
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). ...