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.