Advantages of Facelets
JavaServer Faces technology was created with the intention of working with JavaServer Pages (hereafter referred to as JSP) applications, to provide a clean separation of the presentation and behavior of web applications.
Prior to Facelets, the most commonly used presentation technology for JavaServer Faces applications was JavaServer Pages (JSP). However using JavaServer Faces technology in JSP presents its own difficulties and limitations.
In JSP, elements and components in a web page are processed and rendered in a progressive order. However, JavaServer Faces also provides its own processing and rendering order. This can cause unpredictable behavior when web applications are executed. Facelets provides a better programming and rendering model for JavaServer Faces technology and resolves the issues faced in using JavaServer Faces with JSP.
Templating, reuse of code, and ease of development are important considerations for developers to adopt JavaServer Faces as the platform for large scale projects. By supporting these features, Facelets reduces the UI development and deployment time.
Other advantages include the following:
Faster compilation time
Compile time validation
High performance rendering
Functional extensibility of components and other server-side objects through customization
Support for code reuse through templating and composite components
For more information on templating, see Templating. For more information on composite components, see Composite Components.
Authoring Facelets Pages
Facelets views are usually written using XHTML markup language. This allows Facelets pages to be more portable across diverse development platforms. JavaServer Faces implementations should support all XHTML pages created in conformance with the XHTML Transitional DTD, as listed at http://www.w3.org/TR/xhtml1/#a_dtd_XHTML-1.0-Transitional.
By convention, JavaServer Faces web pages that are authored using Facelets technology have .xhtml extension.
Tag Libraries and EL Support
This section covers the following topics:
Tag Library Support
JavaServer Faces technology uses various tags to express UI components in a web page. Facelets uses the XML namespace declarations to support the JavaServer Faces tag library mechanism. However, for Facelets, the role of tag libraries is not as important as in JSP.
Table Table 6-1 shows the tag libraries supported by Facelets.
Table 6-1 Tag Libraries Supported by Facelets
Tag Library |
URI |
prefix |
Example |
Contents |
|---|---|---|---|---|
JSF UI Tag Library |
http://java.sun.com/jsf/facelets |
ui: |
ui:component ui:insert |
Tags for for templating |
JSF HTML Tag Library |
http://java.sun.com/jsf/html |
h: |
h:head h:body h:outputText h:inputText |
JavaServer Faces component tags for all UIComponent + HTML RenderKit Renderer combinations defined in the JavaServer Faces 2.0 Specification. |
JSF Core Tag Library |
http://java.sun.com/jsf/core |
f: |
f:actionListener f:attribute |
Tags for JavaServer Faces custom actions that are independent of any particular RenderKit. |
JSTL Core Tag Library |
http://java.sun.com/jsp/jstl/core |
fn: |
fn:toUpperCase fn:toLowerCase |
JSTL 1.1 Core Tag Library |
JSTL Functions Library |
http://java.sun.com/jsp/jstl/functions |
c: |
c:forEach c:catch |
JSTL 1.1 Functions Tag Library |
In addition, Facelets also supports composite components for which you can declare custom prefixes. For more information on composite components, see Composite Components.
Unified EL Support
Based on the JavaServer Faces support for unified expression language (EL) syntax defined by JSP 2.1, Facelets supports EL. EL expressions are used to bind UI component objects or values, or managed-bean methods or managed-bean properties. For more information on using EL expressions, see Using the Unified EL to Reference Backing Beans.


