Learn Java for Web Development

(Tina Meador) #1
CHAPTER 6: Component-Based Web Development Using JSF 2 267

Converter and Validator

JSF provides out-of-the-box converters to convert its UI component’s data to objects used in a
managed bean, and vice versa. For example, they convert a component’s Date value to and from
String values that come from the HTML markup.


JSF also provides out-of-the-box validators to validate its UI components to ensure that the value
entered by the user is valid. These tags can, for example, validate a range of Long or the length
of a string.


Events and Event Listeners

When the user clicks a button or link on the JSF page, a JSF UI component triggers an event. To
handle such an event, an event listener is registered on the managed bean. The UI component calls
the event notification on the event listener for the specific event.


As you have seen, JSF pages consist of a tree of components. This tree of components is managed
by the JSF request-processing life cycle behind the scenes. To understand the JSF request-
processing life cycle, first you will create a Hello World web application, and then through this
application you will learn how the JSF life cycle works behind the scenes.


Getting Started with JSF


In this section, you will create a simple Hello World JSF web application using Eclipse 3.8 or
newer, which supports JSF2.x. Create a dynamic web project as illustrated in Figure 6-3 by
selecting File ➤ New ➤ Project ➤ Web ➤ Dynamic Web Project. Specify Apache Tomcat v7.0
in Target Runtime, select JavaServer Faces Project in the configuration, and click Next.

Free download pdf