Week 6

1 Introduction

Facelets provides a powerful templating system that allows you to define the JSF presentation layer using HTML-style templates, reducing redundant code when components are integrated into the presentation layer, without the need for a web container.  
 2. Template framework
Facelets is similar to Tapestry in providing a template framework designed for component building. However, to us with a JSP background, Facelets look a lot more friendly than Tapestry. It allows the use of familiar JSTL-style markup and JSTL/JSF/JSP-style expression languages. A greatly reduced learning curve means that development can be started more quickly.
Facelets and TapestryFacelets are very similar to Tapestry and can be compared to each other. In fact, Tapestry was way ahead of its time when it first appeared, and Facelets did borrow some of its ideas. However, it would be a mistake to think of Facelets only as JSF's version of Tapestry. The two technologies are different. To learn more about Tapestry, see Brett McLaughlin's two-part series "In tune with Tapestry."
Facelets allows you to define sets of components that can be included directly into pages or easily added to the Facelet tag library. It's actually nice to see how quickly custom tags (composite components and JSP custom tags-like tags) can be defined in Facelets. Using these sets of components, Facelets also allow site templates (and smaller templates) to be defined. This is similar to using Tiles, but without the definition file. Facelets can also be used inside custom JSF components because the Facelets API provides an interface that can be easily integrated with JSF components.

Facelets Life Cycle:

 The JavaServer Faces specification defines the life cycle of a JavaServer Faces application. For more information about this lifecycle, see Lifecycle of JavaServer Faces Applications. The following steps describe the process applied to a facelet-based application.
1. When a client (eg browser) makes a new request to a page created with Facelets, a new component tree or javax.faces.component.UIViewRoot will be created and placed in the FacesContext.
2. UIViewRoot is applied to Facelets, and the view is populated with components for presentation.
3. The newly constructed view is returned as a response to the client.
4. When rendered, the state of this view is stored for the next request. Stores the state of input components and form data.
5. Clients can interact with the view and request another view or change from the JavaServer Faces application. At this point, the saved view is restored from the stored state.
6. The restored view goes through the JavaServer Faces lifecycle again, which will eventually generate a new view, or re-render the current view, if there are no validation issues and no action is triggered.
7. If the same view is requested, render the storage view again.
8. If a new view is requested, continue with the process described in step 2.
9. The new view is then returned as a response to the client.

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=324737079&siteId=291194637