Installing and Configuring a JSF Web Application

So far, we’ve looked at a very simple JSP page and how the tag handlers represented in the page use the JSF API to create JSF components behind the scene. Before we look at examples of other features, let’s walk through how to install and run the simple page from Example 6-1.

The JSP page is part of a Java web application. As you may recall from Chapter 4, a Java web application consists of all the application files (JSP files, images, class files, and so on) plus a deployment descriptor (the web.xml file), arranged in a directory structure. A part of the directory structure for the book example application looks like this:

/index.html
/cover.gif
/expense/stage1/filterArea.jsp
...
/WEB-INF/web.xml
/WEB-INF/faces-config.xml
/WEB-INF/lib/jsf-api.jar
/WEB-INF/lib/jsf-impl.jar
...

At the top level, there’s an index.html page with links to all examples in the book. The /expense/stage1/filterArea.jsp file is one of them, containing the code for Example 6-1. So, a JSP page with JSF components is included in a web application just the same as a regular JSP page: as a file in the public part of the directory structure.

You must put at least these two declarations in the WEB-INF/web.xml file for a JSF application:

... <servlet> <servlet-name>FacesServlet</servlet-name> <servlet-class>javax.faces.webapp.FacesServlet</servlet-class> </servlet> <servlet-mapping> <servlet-name>FacesServlet</servlet-name> <url-pattern>*.faces</url-pattern> </servlet-mapping> ...

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.