Tag Library Documentation Generator - Generated Documentation

Tag Libraries
The core JavaServer Faces custom actions that are independent of any particular RenderKit.
This tag library contains JavaServer Faces component tags for all UIComponent + HTML RenderKit Renderer combinations defined in the JavaServer Faces Specification.

Describes the Facelets2 tag library used for declaring and defining the usage contract for composite UI Components. When authoring a composite component, use of this tag library is largely optional, though always recommended. Declaring and defining a composite component with this taglib provides valuable information about the component that can be used by tools and users of the composite component. In most cases, a composite component can be authored without declaring and defining its usage contract with this taglib. PENDING: the limit of what one can do without declaring and defining a usage contract must be cleary specified and documented. PENDING: The implementation team must help discover these limits.

Creating a Composite Component

The default implementation must support authoring A composite component is declared by creating a Facelets2 file inside of a resource library. (See section JSF.2.6 of the specification prose document for more information about resource libraries.) A composite component must reside within a resource library. It is not possible to create a composite component without putting it inside of a resource library.

The default XML namespace URI of the taglib that contains the composite component, for use in the using page, is http://java.sun.com/jsf/composite/<composite-library-name>, where <composite-library-name> is the name of the resource library. For example:

 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" 
<html xmlns="http://www.w3.org/1999/xhtml"

This declares that any Facelets2 file in the resource library called ezcomp can be used as a regular JSF UI component in a page with the above namespace declaration by using the "ez" prefix. For example, placing a file called foo.xhtml in a resource library called ezcomp would make that file accessible like this.

 <ez:foo /> 

The implementation must also support declaring the namespace of the tag library in a JSF PDL tag library descriptor. This descriptor file is optional and is useful for component vendors that do not want to use the default XML namespace. This version of the proposal currently uses the facelet taglib descriptor syntax. For example:


Components from that taglibrary may be used in a using page by declaring them in the XML namespace for that page:

 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" 
<html xmlns="http://www.w3.org/1999/xhtml"

Below is an example of a fairly involved composite component declaration. Such a declaration might appear in foo.xhtml.

  1.                      displayName="Very Simple Login Panel"
  2.                      preferred="true"
  3.                      expert="false"
  4.                      shortDescription="An illustration of the composite component feature">
  5.   <composite:attribute name="model" required="true">
  6.     <composite:attribute name="loginAction" required="true" method-signature="java.lang.Object action()"/ >
  7.   </composite:attribute>
  8.   <composite:attribute name="valueChangeListener" targets="username" />
  9.   <composite:attribute name="specialMethodExpression"
  10.                        method-signature="com.foo.User validateCurrentUser()" />
  11.   <composite:attribute name="loginButtonLabel" default="Login" />
  12.   <composite:editableValueHolder name="username" />
  13.   <composite:actionSource name="loginEvent" />
  14.   <composite:actionSource name="cancelEvent" />
  15.   <composite:actionSource name="allEvents" targets="loginEvent,cancelEvent" />
  16. </composite:interface>
  18.   <ui:decorate template="fooTemplate.xhtml">
  20.     <ui:define name="header">
  22.       <p>This is the login panel header</p>
  24.     </ui:define>
  26.     <ui:define name="body">
  28.       <p>
  30.          <h:inputText id="username" />
  32.       </p>
  34.       <p>
  36.         <h:commandButton id="loginEvent"
  37.                          value="#{cc.attrs.loginButtonLabel}">
  39.         </h:commandButton>
  41.         <h:commandButton id="cancelEvent" value="Cancel" action="cancel">
  43.         </h:commandButton>
  45.         <special:validateUserButton
  46.           validateUser="#{cc.attrs.specialMethodExpression}" />
  49.       </p>
  51.     </ui:define>
  53.     <ui:define name="footer">
  55.      <p>This is the login panel footer</p>
  57.     </ui:define>
  59.   </ui:decorate>
  61. </composite:implementation>

The values for attributes in a composite component PDL file can be fully localized by putting them inside a ResourceBundle in the same directory as the PDL page and accessing them with the per-component resource bundle syntax. Consider the file foo.xhtml, in the resource library ezcomp. The shortDescription element could be changed to be:

 <composite:interface shortDescription="#{cc.resourceBundleMap.shortDescription}" > 

In this case, In the same ezcomp directory as foo.xhtml, there would be a foo.properties file that would contain this entry:

 shortDescription=A really nifty login panel. 

The normal localization rules for ResourceBundle would apply.


The tags in this library add templating—a powerful view composition technique—to JSF. Templating is so useful that there are entire frameworks, such as Tiles and SiteMesh, that are built around the concept of templating. So what is templating, how can you benefit from it, and how does this tag library implement it?

If you've used JSP before, you've probably used jsp:include. The prototypical example for jsp:include is a header on each page in a web application. One JSP page, say header.jsp, encapsulates the header content, and the header is included by each page. You encapsulate and reuse content, so that changes to one file, header.jsp, affect the header on every page.

This tab library contains a tag—ui:include— that's analagous to jsp:include, but encapsulating and reusing content is only half the templating story, because templating also lets you encapsulate and reuse layout. You define a single template (meaning layout), and you reuse that template with multiple compositions. So now you can control the layout of many pages with a single template (layout). Let's take a look at an example.

A Templating Example

First, we define a template:

  1. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
  2.               "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  4. <html xmlns="http://www.w3.org/1999/xhtml"
  5.             xmlns:ui="http://java.sun.com/jsf/facelets"
  6.     <head>
  7.       <link href="styles.css" rel="stylesheet" type="text/css"/>
  8.       <title><ui:insert name="title">Default Title</ui:insert></title>
  9.     </head>
  11.     <body>
  12.       <ui:debug/>
  13.       <div class="heading">
  14.         <ui:insert name="heading"/>
  15.       </div>
  17.       <div class="content">
  18.         <ui:insert name="content"/>
  19.       </div>
  20.     </body>
  21. </html>

In the preceeding listing, we've defined a layout, also known as a template. That template uses the ui:insert tag to insert pieces of a page —namely, title, heading, and content— defined in a composition. Notice that on line 8, we define a default title, in case one isn't provided by the composition. Also note that on line 12 we have the ui:debug tag, which lets the user activate a popup window with debugging information by typing CTRL + Shift + d.

The title, heading, and content pieces of the page referenced in the template are defined in a separate XHTML file in a composition, like this:

  1. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
  2.         "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  4. <html xmlns="http://www.w3.org/1999/xhtml"
  5.    xmlns:ui="http://java.sun.com/jsf/facelets">
  7.   <body>
  8.     <ui:composition template="/layout.xhtml">
  10.       <ui:define name="title">A List of Contacts</ui:define>
  11.       <ui:define name="heading">Contacts</ui:define>
  13.       <ui:define name="content">
  14.         <ui:include src="contactsTable.xhtml" />
  15.       </ui:define>
  17.     </ui:composition>
  18.   </body>
  19. </html>

At runtime, JSF synthesizes the two previous XHTML pages to create a single JSF view by inserting the pieces defined in the composition into the template (that template is layout.xhtml, which is the first listing above). JSF also disregards everything outside of the composition tag so that we don't wind up with two body elements in the view. Also, note that we use the ui:include tag on line 14 to include content (which happens to be a table) from another XHTML page, so that we can reuse that table in other views.

So why do we have two XHTML pages to define a single view? Why not simply take the pieces and manually insert them into the layout so that we have only a single XHTML page? The answer is simple: we have separated layout from the content so that we can reuse that layout among multiple compositions. For example, now we can define another composition that uses the same layout:

  1. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
  2.         "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  4. <html xmlns="http://www.w3.org/1999/xhtml"
  5.       xmlns:ui="http://java.sun.com/jsf/facelets">
  7.   <body>
  8.     <ui:composition template="/layout.xhtml">
  10.       <ui:define name="title">Create a Contact</ui:define>
  11.       <ui:define name="heading">Create Contact</ui:define>
  13.       <ui:define name="content">
  14.         <ui:include src="createContactForm.xhtml"/>
  15.       </ui:define>
  17.     </ui:composition>
  18.   </body>
  19. </html>

By encapsulating the layout, we can reuse that layout among multiple compositions. Just like ui:include lets us encapsulate and reuse conent, JSF compositions let us encapsulate and reuse layout, so that changes to a single layout can affect multiple views. Fundamentally, that's what this tag library is all about.

JSTL core
JSTL 1.2 core library
JSTL functions
JSTL 1.1 functions library

Output Generated by Tag Library Documentation Generator. Java, JSP, and JavaServer Pages are trademarks or registered trademarks of Sun Microsystems, Inc. in the US and other countries. Copyright 2002-4 Sun Microsystems, Inc. 4150 Network Circle Santa Clara, CA 95054, U.S.A. All Rights Reserved.