Stable release | 2.0 / June 28, 2009 |
---|---|
Written in | Java |
Operating system | Cross-platform |
Type | Web template system |
Website | facelets |
Stable release | 1.1.15 / November 24, 2009 |
---|---|
Preview release | 1.2-dev / November 10, 2006 |
Written in | Java |
Operating system | Cross-platform |
Size | 5.07 MB (archived) |
Type | Web template system |
License | Apache License 2.0 |
Website | facelets |
In computing, Facelets is an open-source Web template system under the Apache license and the default view handler technology (aka view declaration language) for Jakarta Faces (JSF; formerly Jakarta Server Faces and JavaServer Faces). The language 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 Faces 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 draws on some of the ideas from Apache Tapestry, [2] [3] and is similar enough to draw comparison. The project is conceptually similar to Tapestry's, which treats blocks of HTML elements as framework components backed by Java classes. Facelets also has some similarities to the Apache Tiles framework with respect to support templating as well as composition.
Facelets was originally created by Jacob Hookom in 2005 [3] 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 by the JSF expert group to be the default view declaration language. JSP has been deprecated as a legacy fall back. [4] [5]
In Facelets, templates tags from a tag library can be entered in two forms: directly as a qualified xml
element or indirectly via the jsfc
attribute on an arbitrary non-qualified element. In the latter case the Facelet compiler will ignore the actual element and will process the element as if it was the one given by the jsfc
attribute.
The following example shows the direct usage of qualified tags:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><htmlxmlns="http://www.w3.org/1999/xhtml"xmlns:h="http://java.sun.com/jsf/html"><body><h:form><h:outputTextvalue="Welcome, #{loggedInUser.name}"disabled="#{empty loggedInUser}"/><h:inputTextvalue="#{bean.property}"/><h:commandButtonvalue="OK"action="#{bean.doSomething}"/></h:form></body></html>
Using the jsfc
attribute, the same code can also be expressed as the example given below:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><htmlxmlns="http://www.w3.org/1999/xhtml"xmlns:h="http://java.sun.com/jsf/html"><body><formjsfc="h:form"><spanjsfc="h:outputText"value="Welcome, #{loggedInUser.name}"disabled="#{empty loggedInUser}"/><inputtype="text"jsfc="h:inputText"value="#{bean.property}"/><inputtype="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 when directly using the qualified tags. Nevertheless, directly using qualified tags is the most popular way of using Facelets in practice [6] and is the style most used in books and examples. [7] [8]
Facelets provides a facility for templating. [9] [10] A Facelets file can reference a master template and provide content for the placeholders this master template defines. The file that references such a template is called the template client. Template clients themselves can again be used as a template for other template clients and as such a hierarchy of templates can be created.
The following shows an example of a simple master template:
templates/master_template.xhtml
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><htmlxmlns="http://www.w3.org/1999/xhtml"xmlns:h="http://java.sun.com/jsf/html"xmlns:ui="http://java.sun.com/jsf/facelets"><h:head><metahttp-equiv="content-type"content="text/html;charset=UTF-8"/><metahttp-equiv="pragma"content="no-cache"/></h:head><h:body>Standardheadertextforeverypage. <ui:insertname="body_content"/>Standardfootertextforeverypage. </h:body></html>
The above code contains a default HTML 'frame' and a single placeholder called body_content. A template client can use this template as follows:
template_client.xhtml
<ui:compositiontemplate="/templates/master_template.xhtml"xmlns="http://www.w3.org/1999/xhtml"xmlns:ui="http://java.sun.com/jsf/facelets"><ui:definename="body_content">Thisisatemplateclientpagethatusesthemastertemplate.</ui:define></ui:composition>
The above code makes use of the template /templates/master_template.xhtml
and provides content for the placeholder in that template. The final result will be a page called template_client.xhtml
that has the content of /templates/master_template.xhtml
, but with <ui:insert name="body_content"/>
replaced by 'This is a template client page that uses the master template.'.
In addition to templating, Facelets provides support for re-use by letting the user include content that resides in a different file. Including such content can be done in three different ways:
The simplest way to include the content of another Facelet is referencing it by name using the <ui:include>
tag. [11] [12] This causes the content in the referenced file to be directly included in the calling Facelet by the Facelets compiler. Besides re-using content at multiple locations, this can be used to break down a large Facelet into smaller parts.
The following shows an example:
templates/master_template.xhtml
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><htmlxmlns="http://www.w3.org/1999/xhtml"xmlns:h="http://java.sun.com/jsf/html"xmlns:ui="http://java.sun.com/jsf/facelets"><ui:includesrc="html_head.xhtml"/><h:body>Standardheadertextforeverypage. <ui:insertname="body_content"/>Standardfootertextforeverypage. </h:body></html>
html_head.xhtml
<ui:compositionxmlns="http://www.w3.org/1999/xhtml"xmlns:h="http://java.sun.com/jsf/html"><h:head><metahttp-equiv="content-type"content="text/html;charset=UTF-8"/><metahttp-equiv=" pragma"content="no-cache"/></h:head></ui:composition>
Facelets supports indirection for including content via custom tags. [13] Such a custom tag can be associated with a Facelet in a taglib file. Occurrences of that tag will then be replaced with the content of the associated Facelet.
The following shows an example of this:
templates/master_template.xhtml
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><htmlxmlns="http://www.w3.org/1999/xhtml"xmlns:h="http://java.sun.com/jsf/html"xmlns:ui="http://java.sun.com/jsf/facelets"xmlns:my="http://example.com/my"><ui:includesrc="html_head.xhtml"/><h:body>Standardheadertextforeverypage.<my:spacer><ui:insertname="body_content"/>Standardfootertextforeverypage. </h:body></html>
The code above uses the tag <my:spacer>
to mark the point in the Facelet where content is to be inserted. Such a tag has to be declared in a Taglib file where it can be associated with a Facelet as follows:
example.taglib.xml
<?xml version="1.0" encoding="UTF-8"?><facelet-taglibxmlns="http://java.sun.com/xml/ns/javaee"xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-facelettaglibrary_2_0.xsd"version="2.0"><namespace>http://example.com/my</namespace><tag><tag-name>spacer</tag-name><source>spacer.xhtml</source></tag></facelet-taglib>
The following shows an example of what the actual content Facelet could look like:
spacer.xhtml
<ui:compositionxmlns="http://www.w3.org/1999/xhtml"xmlns:ui="http://java.sun.com/jsf/facelets"xmlns:h="http://java.sun.com/jsf/html"><h:outputTextvalue="&nbsp;"escape="false"/></ui:composition>
Besides including content directly, Facelets provides the composite component mechanism that makes content available as a first-class JSF component. [14] [15] Composite components do not need to be declared in a Taglib file, but instead have to be put in a special directory. By convention the content is then automatically assigned a namespace and a tag name. The namespace is constructed of the fixed string 'http://java.sun.com/jsf/composite/' concatenated with the directory name in which the content file resides relative to the 'resources' directory. [16] The tag name becomes the file name without the .xhtml suffix.
The following shows an example of this:
resources/my/spacer.xhtml
<ui:compositionxmlns="http://www.w3.org/1999/xhtml"xmlns:ui="http://java.sun.com/jsf/facelets"xmlns:h="http://java.sun.com/jsf/html"xmlns:cc="http://java.sun.com/jsf/composite"><cc:interface/><cc:implementation><h:outputTextvalue="&nbsp;"escape="false"/></cc:implementation></ui:composition>
The above Facelet is automatically available as a component in namespace 'http://java.sun.com/jsf/composite/my' and tag name 'spacer'
To customize included content, Facelets allows parameters to be used. Via those parameters, objects can be passed into the included content, where they can be used as variables. For the <ui:include>
mechanism the <ui:param>
can be used for this, [17] while for the custom tags and composite components, normal tag attributes can be used. Composite components require parameters to be declared in their interface section, [18] while for custom tags there is no such requirement and values provided for arbitrary attributes are made available as variables with the same name as said attribute.
A document type definition (DTD) is a specification file that contains set of markup declarations that define a document type for an SGML-family markup language. The DTD specification file can be used to validate documents.
HyperText Markup Language or HTML is the standard markup language for documents designed to be displayed in a web browser. It defines the content and structure of web content. It is often assisted by technologies such as Cascading Style Sheets (CSS) and scripting languages such as JavaScript.
Mathematical Markup Language (MathML) is a mathematical markup language, an application of XML for describing mathematical notations and capturing both its structure and content, and is one of a number of mathematical markup languages. Its aim is to natively integrate mathematical formulae into World Wide Web pages and other documents. It is part of HTML5 and standardised by ISO/IEC since 2015.
XHTML Basic is an XML-based structured markup language primarily designed for simple user agents, often found in mobile devices such as mobile phones, PDAs, pagers, and set-top boxes..
Jakarta Faces, formerly Jakarta Server Faces and JavaServer Faces (JSF) is a Java specification for building component-based user interfaces for web applications. It was formalized as a standard through the Java Community Process as part of the Java Platform, Enterprise Edition. It is an MVC web framework that simplifies the construction of user interfaces (UI) for server-based applications by using reusable UI components in a page.
XInclude is a generic mechanism for merging XML documents, by writing inclusion tags in the "main" document to automatically include other documents or parts thereof. The resulting document becomes a single composite XML Information Set. The XInclude mechanism can be used to incorporate content from either XML files or non-XML text files.
Apache Wicket, commonly referred to as Wicket, is a component-based web application framework for the Java programming language conceptually similar to JavaServer Faces and Tapestry. It was originally written by Jonathan Locke in April 2004. Version 1.0 was released in June 2005. It graduated into an Apache top-level project in June 2007.
Apache Tapestry is an open-source component-oriented Java web application framework conceptually similar to JavaServer Faces and Apache Wicket. Tapestry was created by Howard Lewis Ship, and was adopted by the Apache Software Foundation as a top-level project in 2006.
In computing, quirks mode is an approach used by web browsers to maintain backward compatibility with web pages designed for old web browsers, instead of strictly complying with web standards in standards mode. This behavior has since been codified, so what was previously standards mode is now referred to as simply no quirks mode.
RDFa or Resource Description Framework in Attributes is a W3C Recommendation that adds a set of attribute-level extensions to HTML, XHTML and various XML-based document types for embedding rich metadata within Web documents. The Resource Description Framework (RDF) data-model mapping enables its use for embedding RDF subject-predicate-object expressions within XHTML documents. It also enables the extraction of RDF model triples by compliant user agents.
Haml is a templating system that is designed to avoid writing inline code in a web document and make the HTML cleaner. Haml gives you the flexibility to have some dynamic content in HTML. Similar to other template systems like eRuby, Haml also embeds some code that gets executed during runtime and generates HTML code in order to provide some dynamic content. In order to run Haml code, files need to have a .haml extension. These files are similar to .erb or .eRuby files, which also help embed Ruby code while developing a web application.
RichFaces was an open source Ajax-enabled component library for JavaServer Faces, hosted by JBoss. It allows easy integration of Ajax capabilities into enterprise application development. It reached its end-of-life in June 2016.
XML documents typically refer to external entities, for example the public and/or system ID for the Document Type Definition. These external relationships are expressed using URIs, typically as URLs.
JBoss Tools is a set of Eclipse plugins and features designed to help JBoss and JavaEE developers develop applications. It is an umbrella project for the JBoss developed plugins that will make it into JBoss Developer Studio.
Extensible HyperText Markup Language (XHTML) is part of the family of XML markup languages which mirrors or extends versions of the widely used HyperText Markup Language (HTML), the language in which Web pages are formulated.
CE-HTML is an XHTML-based standard for designing webpages with remote user interfaces for consumer electronic devices on Universal Plug and Play networks. The standard is intended for defining user interfaces that can gracefully scale on a variety of screen sizes and geometries, including those of mobile devices to high definition television sets.
Apache Click is a page and component oriented web application framework for the Java language and is built on top of the Java Servlet API.
Java view technologies and frameworks are web-based software libraries that provide the user interface, or "view-layer", of Java web applications. Such application frameworks are used for defining web pages and handling the HTTP requests (clicks) generated by those web pages. As a sub-category of web frameworks, view-layer frameworks often overlap to varying degrees with web frameworks that provide other functionality for Java web applications.
XHTML+RDFa is an extended version of the XHTML markup language for supporting RDF through a collection of attributes and processing rules in the form of well-formed XML documents. XHTML+RDFa is one of the techniques used to develop Semantic Web content by embedding rich semantic markup. Version 1.1 of the language is a superset of XHTML 1.1, integrating the attributes according to RDFa Core 1.1. In other words, it is an RDFa support through XHTML Modularization.
A document type declaration, or DOCTYPE, is an instruction that associates a particular XML or SGML document with a document type definition (DTD). In the serialized form of the document, it manifests as a short string of markup that conforms to a particular syntax.
The expert group decided to move forward with Facelets as the basis for new features while letting JSP remain as a backward compatibility layer.
Facelets is a replacement for JSP that was designed from the outset with JSF in mind. New features introduced in version 2 and later are only exposed to page authors using Facelets. JSP is retained for backwards compatibility.