Running a JSP Page Containing JSF Components

If you have installed the example web application as described in Chapter 3, you’ve copied the whole directory structure to Tomcat’s webapps directory as a subdirectory named jsfbook. If so, you can run the JSP page in Example 6-1 by typing the URL http://localhost:8080/jsfbook/expense/stage1/filterArea.faces in a browser. The result is shown in Figure 6-2.

There are a couple of things to note about the URL used to run the page. First, the path starts with a /jspbook prefix. This is the application’s context path. A Java web application is always associated with a context path when it’s deployed to a web container, as you may recall from Chapter 4. When you use Tomcat, the context path is, by default, the name of the webapps subdirectory that holds the application. For other containers, you may be prompted for a name when you install the application. The second thing to note is that the URL ends with .faces. This is the extension we mapped to the JSF servlet in the deployment descriptor, so you must use this extension for all JSF page requests to have them processed by the JSF implementation. As I mentioned earlier, JSF replaces the extension with .jsp to get the context-relative path to the JSP page that creates the JSF components.

When you request this page the first time, JSF processes it as a regular JSP page. The tag handlers for the JSF actions in the page create their corresponding JSF components, configure them using the action ...

Get JavaServer Faces now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.