Chapter 21. JavaServer Faces

The last few chapters introduced you to the Model View Controller (MVC) design pattern and to the Struts, WebWork, and Spring frameworks that implement the pattern for Web-based applications. Struts has been around for some time, and is a proven framework for developing high-quality Web applications. However, the Java community has long desired a way to create components that can be used in Web applications in a manner similar to the way in which components are used in Swing or AWT-based applications. Enter the JavaServer Faces technology (JSF). Struts developers should feel comfortable with JSF because they share a number of similarities, as you will discover in this chapter. That is not an accident: One of the primary developers for Struts is also a primary developer for JSF. JSF may have one long-term advantage over Struts as a framework: JSF is to be included as part of a future J2EE standard. In this chapter, you will explore building Web applications using JSF.

In particular you will learn the following:

  • How to configure a JSF project

  • The JSF lifecycle

  • How to validate data

  • How to convert data

  • How to handle events with listeners

Configuring a JSF Project

Because you will be working with a JavaServer Faces application right away, you will need to have a project set up with the correct directory structure, as shown in Figure 21-1.

Directory structure for a JavaServer Faces application

Figure 21.1. Directory structure ...

Get Beginning JavaServer Pages™ 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.