Structure of a JSF Application
JSF applications are web applications built on the Java Servlet framework, so they follow the same general packaging scheme as any other J2EE application (see Chapter 2 for more information). The jar files for the JSF implementation must be available on the web application’s classpath (usually accomplished by putting the appropriate jar files into the WEB-INF/lib directory).
For the reference implementation, the FacesServlet
must be configured in the
web.xml file for the application. This servlet
provides the JSF engine: it’s responsible for processing requests for
JSF-based pages and returning the UI in HTML format. For our example,
we’re going to treat all resources with a .faces
extension as a JSF target, so we configure the FacesServlet
like this:
<servlet> <servlet-name>Faces Servlet</servlet-name> <servlet-class>javax.faces.webapp.FacesServlet</servlet-class> <load-on-startup>1</load-on-startup> </servlet> <!-- Faces Servlet Mapping --> <servlet-mapping> <servlet-name>Faces Servlet</servlet-name> <url-pattern>*.faces</url-pattern> </servlet-mapping>
Mapping *.faces to the FacesServlet
instructs the servlet container
to delegate all requests ending with .faces to
the JSF engine.
JSF Lifecycle
So what happens when a request is sent to the JSF engine? In short, the JSF engine creates a tree containing a set of “components,” each corresponding to an element of the user interface for the page being submitted, and ensures that the correct user values are ...
Get Java Enterprise in a Nutshell, Third Edition 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.