JavaServer Faces, more often referred to as jsf or simply Faces, is a set of technologies for developing M - V - C user interfaces 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 analogous to Struts, but has a different flavor and feel. Put another way, it embodies a different conceptual or programming model.
Struts is very protocol oriented. That is, the designer or programmer is likely to visualize a jsp being displayed on the user's browser. When the user selects 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 daatabse. 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 flow directly between components, even when those components are distributed across the network, rather than through some central i/o channel.
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. Although these jsps are defined using the conventional .jsp suffix, when they are referenced in a URL, a .jsf suffix is used instead. Thus, to actually access, say, a login.jsp page, one would use login.jsf.
Faces differs most from Struts in its 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 sometimes referred to as ManagedBeans. Like a conventional DataBean, they include private properties, public getter and setter methods, and a no-argument constructor. These properties will 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 might 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.
Development Environment
JSPs
ManagedBeans
Session State
Configuration files
Deployment
Resources
- Apache MyFaces Project
- Amateras documentation and download link for facesIDE plugin for Eclipse.
- Sun's Faces Project Page
- Sun's Faces documentation, inlcuding APIs.
- Pointers to numerous Faces tutorials and other resources.
- Rick Hightower's excellent tutorial on Faces validation (includes pointers to other articles in a series)
- Marty Halls excellent lessons on jsf.
- Sun's Java EE Tutotial, which includes chapters on Faces.
- Exadel's JSF Kickstart tutorial
- Srikanath Shenoy & Nithin Mallya, Integrating Struts, Tiles, and JavaServer Faces, IBM.