Facelets
Stable release | 1.1.15
/ November 24, 2009 |
---|---|
Preview release | 1.2-dev
/ November 10, 2009 |
Written in | Java |
Operating system | Cross-platform |
Size | 5.07 MB (archived) |
Type | Web Framework |
License | Apache License 2.0 |
Website | http://facelets.dev.java.net/ |
Facelets is an open source web framework under the Apache license and the default view handler technology (aka view declaration language) for JavaServer Faces (JSF). The framework requires valid input XML documents to work. Facelets supports all of the JSF UI components and focuses completely on building the JSF component tree, reflecting the view for a JSF application.
Although both JSP and JSF technologies have been improved to work better together, Facelets eliminates the issues noted in Hans Bergsten's article "Improving JSF by Dumping JSP"[1]
Facelets is similar enough to Apache Tapestry to draw comparison. In fact, Tapestry was well ahead of its time when it first came out [neutrality is disputed], and Facelets does draw on some of its ideas. The project is conceptually similar to Tapestry's, which uses the jwcid
attribute, while Facelets uses the jsfc
attribute combined with proper namespaces to convert HTML elements into the corresponding JSF components. Also, there are some similarities to the Tiles framework regarding support templating as well as composition.
Initially, Facelets was available as a separate, alternative view declaration language for JSF 1.1 and JSF 1.2 which both used JSP as the default view declaration language. Starting from JSF 2.0, Facelets has been promoted as the default, and JSP has been deprecated as a legacy fall back [2].
Example
The following example shows an XHTML template for taking the use of Facelets component-aliasing. The jsfc
attribute is used here, shows which tags to replace when compiling the page with the corresponding JavaServer Faces components.
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0
Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xmlns:h="http://java.sun.com/jsf/html">
<body>
<form jsfc="h:form">
<span jsfc="h:outputText" value="Welcome, #{loggedInUser.name}" disabled="#{empty loggedInUser}" />
<input type="text" jsfc="h:inputText" value="#{bean.property}" />
<input type="submit" jsfc="h:commandButton" value="OK" action="#{bean.doSomething}" />
</form>
</body>
</html>
The above code can be viewed in a browser, and edited with conventional WYSIWYG design tools. This is not possible with regular JSF 1.2 pages (shown below the same functionality).
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0
Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xmlns:h="http://java.sun.com/jsf/html">
<body>
<h:form>
<h:outputText value="Welcome, #{loggedInUser.name}" disabled="#{empty loggedInUser}" />
<h:inputText value="#{bean.property}" />
<h:commandButton value="OK" action="#{bean.doSomething}" />
</h:form>
</body>
</html>
See also
References
- ^ Hans Bergsten (June 6, 2004). "Improving JSF by Dumping JSP". O'Reilly Media.
- ^ JavaServer Faces 2.0, The Complete Reference by Ed Burns and Chris Schal, page 55: 'The expert group decided to move forward with Facelets as the basis for new features while letting JSP remain as a backward compatibility layer'.
Bibliography
- Wadia, Zubin; Marinschek, Martin; Saleh, Hazem; Byrne, Dennis (September 22, 2008), The Definitive Guide to Apache MyFaces and Facelets (1st ed.), Apress, p. 400, ISBN 978-1590597378
- Wadia, Zubin; Aranda, Bruno (May 26, 2008), Facelets Essentials: Guide to JavaServer Faces View Definition Framework (1st ed.), Apress, p. 84, ISBN 978-1430210498