Book Image

JSF 1.2 Components

By : IAN HLAVATS
Book Image

JSF 1.2 Components

By: IAN HLAVATS

Overview of this book

Today's web developers need powerful tools to deliver richer, faster, and smoother web experiences. JavaServer Faces includes powerful, feature-rich, Ajax-enabled UI components that provide all the functionality needed to build web applications in a Web 2.0 world. It's the perfect way to build rich, interactive, and "Web 2.0-style" Java web apps. This book provides a comprehensive introduction to the most popular JSF components available today and demonstrate step-by-step how to build increasingly sophisticated JSF user interfaces with standard JSF, Facelets, Apache Tomahawk/Trinidad, ICEfaces, JBoss Seam, JBoss RichFaces/Ajax4jsf, and JSF 2.0 components. JSF 1.2 Components is both an excellent starting point for new JSF developers, and a great reference and “how to” guide for experienced JSF professionals. This book progresses logically from an introduction to standard JSF HTML, and JSF Core components to advanced JSF UI development. As you move through the book, you will learn how to build composite views using Facelets tags, implement common web development tasks using Tomahawk components, and add Ajax capabilities to your JSF user interface with ICEfaces components. You will also learn how to solve the complex web application development challenges with the JBoss Seam framework. At the end of the book, you will be introduced to the new and up-coming JSF component libraries that will provide a road map of the future JSF technologies.
Table of Contents (14 chapters)
JSF 1.2 Components
Credits
Foreword
About the Author
About the Reviewers
Preface

Chapter 1. Standard JSF Components

The components and examples covered in this chapter have been selected to introduce a number of important concepts for developing JSF user interfaces. It is necessary to understand the basic JSF components because they are the building blocks from which other components and component libraries are derived.

We will begin by looking at a number of common web application development tasks and how they can be implemented using standard JSF components. In the process, we will learn how to use other JSF artifacts, such as managed beans, converters, validators, and more.

An introduction to JSF

While the main focus of this book is learning how to use JSF UI components, and not to cover the JSF framework in complete detail, a basic understanding of fundamental JSF concepts is required before we can proceed. Therefore, by way of introduction, let's look at a few of the building blocks of JSF applications: the Model-View-Controller architecture, managed beans, EL expressions, converters, and validators.

The Model-View-Controller architecture

JSF is based on the Model-View-Controller (MVC) architecture. The Model in MVC represents the data of the application, and is typically implemented using Plain Old Java Objects (POJOs) based on the JavaBeans API. The View in MVC represents the user interface of the application and is responsible for rendering data and user interface controls to the user. The Controller in MVC represents an object that responds to user interface events and deals with querying or modifying the Model.

Managed beans

Managed beans are the Controllers of a JSF application, handling events in the user interface and updating the Model in response to user interaction. A managed bean is simply a Java class with instance variables and methods that are coupled to the application's domain model and to JSF's event handling API.

The JSF Expression Language (JSF EL)

The JSF Expression Language (JSF EL) is a simple, powerful, object-oriented, and typesafe scripting language used to bind UI components to managed bean properties and methods. The following example shows how to display a customized welcome message that references a backing bean property using the JSF EL:

<h:outputText value="Hello, #{backingBean.username}" />

Converters and validators

JSF includes standard converters for common data types such as numbers, Boolean values, and dates, and also supports custom converters for handling user-defined data types. Additionally, JSF includes standard validators for typical input validation scenarios such as checking required fields and numbers, and also supports custom validators. We will see a number of both, standard converters and validators and custom convertors and validators, throughout this book.