Behind the Scenes

JSF Framework Services

Now that you have seen your first JSF application, it is easier to explain the services that the JSF framework offers to developers. Figure 1-12 gives a high-level overview of the JSF architecture. As you can see, the JSF framework is responsible for interacting with client devices, and it provides tools for tying together the visual presentation, application logic, and business logic of a web application. However, the scope of JSF is restricted to the presentation tier. Database persistence, web services, and other backend connections are outside the scope of JSF.

Figure 1-12. High-level overview of the JSF framework


Here are the most important services that the JSF framework provides:

Model-view-controller architecture All software applications let users manipulate certain data, such as shopping carts, travel itineraries, or whatever data is required in a particular problem domain. This data is called the model. Just as an artist creates a painting of a model in a studio, a software developer produces views of the data model. In a web application, HTML (or a similar rendering technology) is used to paint these views.

JSF connects the view and the model. As you have seen, a view component can be wired to a bean property of a model object, such as

<h:inputText value="#{user.name}"/>

Moreover, JSF operates as the controller that reacts to the user by processing action and value change events, routing them to code that updates the model or the view. For example, you may want to invoke a method to check whether a user is allowed to log on. Use the following JSF tag:

<h:commandButton value="Login" action="#{user.check}"/>

When the user clicks the button and the form is submitted to the server, the JSF implementation invokes the check method of the user bean. That method can take arbitrary actions to update the model, and it returns the navigation ID of the next page to be displayed. We discuss this mechanism further in "Dynamic Navigation" on page 73 of Chapter 3.

Thus, JSF implements the classical model-view-controller architecture.

Data conversion Users enter data into web forms as text. Business objects want data as numbers, dates, or other data types. As explained in Chapter 6, JSF makes it easy to specify and customize conversion rules.

Validation and error handling JSF makes it easy to attach validation rules for fields such as "this field is required" or "this field must be a number". Of course, when users enter invalid data, you need to display appropriate error messages. JSF takes away much of the tedium of this programming task. We cover validation in Chapter 6.

Internationalization JSF manages internationalization issues such as character encodings and the selection of resource bundles. We cover resource bundles in "Message Bundles" on page 42 of Chapter 2.

Custom components Component developers can develop sophisticated components that page designers simply drop into their pages. For example, suppose a component developer produces a calendar component with all the usual bells and whistles. You just use it in your page, with a command such as

<acme:calendar value="#{flight.departure}" startOfWeek="Mon"/>

Chapter 9 covers custom components in detail.

Alternative renderers By default, JSF generates markup for HTML pages. But it is easy to extend the JSF framework to produce markup for another page description language such as WML or XUL. The book's companion site contains a chapter that shows you how to use JSF to communicate with Java ME-powered cell phones.

Tool support JSF is optimized for use with automated tools. As these tools mature in the coming years, we believe that JSF will be the must-have framework for developing web interfaces with Java.



Core JavaServerT Faces
Core JavaServer(TM) Faces (2nd Edition)
ISBN: 0131738860
EAN: 2147483647
Year: 2004
Pages: 84

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net