Jump to content

Facelets

From Wikipedia, the free encyclopedia

This is an old revision of this page, as edited by Tritium6 (talk | contribs) at 17:05, 7 June 2010 (spelling). The present address (URL) is a permanent link to this revision, which may differ significantly from the current revision.

Facelets
Stable release
1.1.15 / November 24, 2009 (2009-11-24)
Preview release
1.2-dev / November 10, 2009 (2009-11-10)
Written inJava
Operating systemCross-platform
Size5.07 MB (archived)
TypeWeb Framework
LicenseApache License 2.0
Websitehttp://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

  1. ^ Hans Bergsten (June 6, 2004). "Improving JSF by Dumping JSP". O'Reilly Media.
  2. ^ 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