Introduction to Java Facelets
- What Is Facelets?
- Developing a Simple Facelets Application
- Templating
- Composite Components
- Resources
The term Facelets refers to the view declaration language for JavaServer Faces technology. JavaServer Pages (JSP) technology, previously used as the presentation technology for JavaServer Faces, does not support all the new features available in JavaServer Faces 2.0. JSP technology is considered to be a deprecated presentation technology for JavaServer Faces 2.0. Facelets is a part of the JavaServer Faces specification and also the preferred presentation technology for building JavaServer Faces technology-based applications.
The following topics are addressed here:
- "What Is Facelets?" on page 83
- "Developing a Simple Facelets Application" on page 85
- "Templating" on page 91
- "Composite Components" on page 94
- "Resources" on page 96
What Is Facelets?
Facelets is a powerful but lightweight page declaration language that is used to build JavaServer Faces views using HTML style templates and to build component trees. Facelets features include the following:
- Use of XHTML for creating web pages
- Support for Facelets tag libraries in addition to JavaServer Faces and JSTL tag libraries
- Support for the Expression Language (EL)
- Templating for components and pages
Advantages of Facelets for large-scale development projects include the following:
- Support for code reuse through templating and composite components
- Functional extensibility of components and other server-side objects through customization
- Faster compilation time
- Compile-time EL validation
- High-performance rendering
In short, the use of Facelets reduces the time and effort that needs to be spent on development and deployment.
Facelets views are usually created as XHTML pages. JavaServer Faces implementations support XHTML pages created in conformance with the XHTML Transitional Document Type Definition (DTD), as listed at http://www.w3.org/TR/xhtml1/#a_dtd_XHTML-1.0-Transitional. By convention, web pages built with XHTML have an .xhtml extension.
JavaServer Faces technology supports various tag libraries to add components to a web page. To support the JavaServer Faces tag library mechanism, Facelets uses XML namespace declarations. Table 5–1 lists the tag libraries supported by Facelets.
Table 5.1. Tag Libraries Supported by Facelets
Tag Library |
URI |
Prefix |
Example |
Contents |
JavaServer Faces Facelets Tag Library |
ui: |
ui:component ui:insert |
Tags for templating |
|
JavaServer Faces HTML Tag Library |
h: |
h:head h:body h:outputText h:inputText |
JavaServer Faces component tags for all UIComponents |
|
JavaServer Faces Core Tag Library |
f: |
f:actionListener f:attribute |
Tags for JavaServer Faces custom actions that are independent of any particular RenderKit |
|
JSTL Core Tag Library |
c: |
c:forEach c:catch |
JSTL 1.1 Core Tags |
|
JSTL Functions Tag Library |
fn: |
fn:toUpperCase fn:toLowerCase |
JSTL 1.1 Functions Tags |
In addition, Facelets supports tags for composite components for which you can declare custom prefixes. For more information on composite components, see "Composite Components" on page 94.
Based on the JavaServer Faces support for Expression Language (EL) syntax defined by JSP 2.1, Facelets uses EL expressions to reference properties and methods of backing beans. EL expressions can be used to bind component objects or values to methods or properties of managed beans. For more information on using EL expressions, see "Using the EL to Reference Backing Beans" on page 161.