Jump to content

Facelets: Difference between revisions

From Wikipedia, the free encyclopedia
Content deleted Content added
No edit summary
No edit summary
Line 16: Line 16:
| website = http://facelets.dev.java.net/
| website = http://facelets.dev.java.net/
}}
}}
'''Facelets''', short for [[JavaServer Faces]] is an alternative view handler technology for the Java Server Faces (JSF). The framework require a valid input [[XML]] documents to work and is mean that all web pages must be valid [[XHTML]] format. Facelets supports all of the [[JavaServer Faces|JSF]] UI components and builds its own component tree, reflecting the '''view''' for a JSF application. Although both [[JavaServer Pages|JSP]] and [[JavaServer Faces|JSF]] technologies have been improved to work better together, Facelets eliminates the issues noted in [[Hans Bergsten]]'s article "Improving JSF by Dumping JSP"<ref>{{cite web
'''Facelets''', short for [[JavaServer Faces]] is an alternative view handler technology for the Java Server Faces (JSF). The framework a valid input [[XML]] documents to work and is mean that all web pages must be valid [[XHTML]] format. Facelets supports all of the [[JavaServer Faces|JSF]] UI components and builds its own component tree, reflecting the '''view''' for a JSF application. Although both [[JavaServer Pages|JSP]] and [[JavaServer Faces|JSF]] technologies have been improved to work better together, Facelets eliminates the issues noted in [[Hans Bergsten]]'s article "Improving JSF by Dumping JSP"<ref>{{cite web
| url = http://onjava.com/pub/a/onjava/2004/06/09/jsf.html
| url = http://onjava.com/pub/a/onjava/2004/06/09/jsf.html
| title = Improving JSF by Dumping JSP
| title = Improving JSF by Dumping JSP
Line 27: Line 27:


Facelets are similar to [[Java:_View_Technologies_and_Frameworks#Tiles|Tiles]] framework and support templating as well as composition.
Facelets are similar to [[Java:_View_Technologies_and_Frameworks#Tiles|Tiles]] framework and support templating as well as composition.

==Example==
The following example shows an XHTML template for taking the use of Facelets component-aliasing. The Jsfc attribute is used here, which tags to replace when compiling the page with the corresponding JavaServer Faces components. In addition, logged in users are welcomed (for the demonstration of the [[Expression Language]]).

<source lang=html4strict>
<!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="Willkommen #{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>
</source>

The above code can be viewed in a browser, and edited with conventional [[WYSIWYG]] design tools. This is not possible with regular JSF pages shown bellow the same functionality.

<source lang=html4strict>
<!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="Willkommen #{loggedInUser.name}" disabled="#{empty loggedInUser}" />
<h:inputText value="#{bean.property}" />
<h:commandButton value="OK" action="#{bean.doSomething}" />
</h:form>
</body>
</html>
</source>


==References==
==References==

Revision as of 21:17, 4 September 2009

Facelets
Stable release
1.1.14 / April 15, 2008 (2008-04-15)
Written inJava
Operating systemCross-platform
Size6.31 MB (archived)
TypeWeb Framework
LicenseApache License 2.0
Websitehttp://facelets.dev.java.net/

Facelets, short for JavaServer Faces is an alternative view handler technology for the Java Server Faces (JSF). The framework requires a valid input XML documents to work and is mean that all web pages must be valid XHTML format. Facelets supports all of the JSF UI components and builds its own 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 designer friendly. Taking from Apache Tapestry's jwcid attribute, Facelets uses jsfc and proper namespaces to convert HTML elements to their associated JSF component.

Facelets are similar to Tiles framework and support templating as well as composition.

Example

The following example shows an XHTML template for taking the use of Facelets component-aliasing. The Jsfc attribute is used here, which tags to replace when compiling the page with the corresponding JavaServer Faces components. In addition, logged in users are welcomed (for the demonstration of the Expression Language).

<!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="Willkommen #{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 pages shown bellow 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="Willkommen #{loggedInUser.name}" disabled="#{empty loggedInUser}" />
   <h:inputText value="#{bean.property}" />
   <h:commandButton value="OK" action="#{bean.doSomething}" /> 
  </h:form>
 </body>
</html>

References

  1. ^ Hans Bergsten (June 6, 2004). "Improving JSF by Dumping JSP". O'Reilly Media.

Bibliography

See also