JavaServer Faces VDL Documentation (2.3 SNAPSHOT 20151009-1818)

Tag Libraries 
LibraryDescription
cc

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.

Creating a Composite Component

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://xmlns.jcp.org/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" 
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:h="http://xmlns.jcp.org/jsf/html"
xmlns:f="http://xmlns.jcp.org/jsf/core"
xmlns:ui="http://xmlns.jcp.org/jsf/facelets"
xmlns:ez="http://xmlns.jcp.org/jsf/composite/ezcomp">
...

This declares that any Facelets2 file in the resource library called ezcomp can be used as a regular JSF UI component in a view 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 VDL 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:


<facelet-taglib>
<namespace>http://domain.com/path</namespace>
<composite-library-name>compositeTest</composite-library-name>
</facelet-taglib>

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


<!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://xmlns.jcp.org/jsf/html"
xmlns:f="http://xmlns.jcp.org/jsf/core"
xmlns:ui="http://xmlns.jcp.org/jsf/facelets"
xmlns:ez="http://domain.com/path/namespace">
...

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>
  17.  
  18.   <ui:decorate template="fooTemplate.xhtml">
  19.  
  20.     <ui:define name="header">
  21.  
  22.       <p>This is the login panel header</p>
  23.  
  24.     </ui:define>
  25.  
  26.     <ui:define name="body">
  27.  
  28.       <p>
  29.  
  30.          <h:inputText id="username" />
  31.  
  32.       </p>
  33.  
  34.       <p>
  35.  
  36.         <h:commandButton id="loginEvent"
  37.                          value="#{cc.attrs.loginButtonLabel}">
  38.  
  39.         </h:commandButton>
  40.  
  41.         <h:commandButton id="cancelEvent" value="Cancel" action="cancel">
  42.  
  43.         </h:commandButton>
  44.  
  45.         <special:validateUserButton
  46.           validateUser="#{cc.attrs.specialMethodExpression}" />
  47.  
  48.  
  49.       </p>
  50.  
  51.     </ui:define>
  52.  
  53.     <ui:define name="footer">
  54.  
  55.      <p>This is the login panel footer</p>
  56.  
  57.     </ui:define>
  58.  
  59.   </ui:decorate>
  60.  
  61. </composite:implementation>

The values for attributes in a composite component VDL file can be fully localized by putting them inside a ResourceBundle in the same directory as the VDL view 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.

Refer to the composite tag for the details of defining the interface and implementation for composite components.


f The core JavaServer Faces custom actions that are independent of any particular RenderKit.