javaServer Faces

JavaServer Faces, more often referred to as jsf or simply Faces, is a set of technologies for developing M - V - C user interfaces and control components for Web-based applications, especially those supported by Servlet engines or Web Containers.  It was originally developed by a consortium including Sun, IBM, BEA, and Oracle but has since migrated to the Apache Foundation.  Their MyFaces site is a good place to start when looking for specs, downloads, and documentation, including APIs.

Faces is similar to Struts, but has a different flavor and feel.  Put another way, it embodies a different conceptual or programming model.

Struts is protocol oriented.  That is, the designer or programmer is likely to visualize the user-system interaction cycle as beginning with a jsp, that normally includes and HTML form, that is displayed on the user's browser.   When the user clicks a button, a message is sent via HTTP to the server where it is processed, first, by the Struts ActionServlet and, then, by a particular Action class.  That action may interact with a backend model and/or database.  When the action component completes its work, navigation normally proceeds to another jsp page, which is sent via HTTP to the user's browser for display, and the cycle begins again.

Faces is much more object-oriented.  That is, the designer or programmer is likely to visualize an architecture much more like the event-listener structure used in Java applications and Applets.  When a user interacts with an interface component, such as a button or a textfield, listening components may be notified of the actions or changes to the data.  These backend components may, in turn, interact with a backend model and/or database.  They are then likely to update the data components displayed to the user, and the cycle begins again.  The important distinction is that Faces supports the illusions that events and data flow directly between components, even when those components are distributed across the network, rather than through some protocol-based channel, as is the case with Struts. 

In fact, however, "under the hood," the basic implementation structure of Faces is much like that of Struts.  Like Struts, Faces uses JavaServer Pages (jsps) as view components.  Like Struts, Faces' jsps use special taglibs, albeit different ones form those used in Struts.  And both systems use a central control servlet as the point of contact between view components and control components.

Faces differs most from Struts in its second-level control components.  Struts uses an Action class to provide the functional part of the control architecture and a FormBean to deliver view data to the action class.  It's then up to the action object to extract the FormBean's properties in order to process them.  Faces combines the function of the Struts FormBean and Action class into a single class. These classes are referred to as ManagedBeans.  Like a conventional DataBean, they include private properties, public getter and setter methods, and a no-argument constructor.  These properties normally correspond to input fields in the view object.  ManagedBeans can also include a set of processing functions, such as add, delete, update, etc., that correspond with a set of buttons on a form.  Then, when a user presses, say, an add button, the add function will be called and any data values in the view's input fields will automatically have been transferred to the ManagedBeans properties.  Of course, there is a FacesServlet, comparable to Strut's ActionServlet and a lot of other infrastructure operating behind the scene, but the programmer is largely unaware of this.

As with Struts, Faces is likely to make use of a model layer for more extensive function and/or interaction with a database.  This is not part of Faces, per se, and Faces is unlikely to have requirements that differ from those of other frameworks.

The discussions outlined below provide additional details ranging from setting up a development environment, to building the various layers and components for a Faces implementation, to deployment.  See especially, the final section that lists references to other resources.  Several especially good tutorials include Richard Hightower's four JSF for Nonbelievers tutorials, starting with Clearing the FUD about JSF.


Development Environment

 


JSPs

 


ManagedBeans

 


Session State

 


Configuration files

 


Handling Images
 


Handling Dynamic Lists and Tables

 


Data Validation

 


Deployment

 


Resources