JSF 2 composite Tag Library

JSF 2 composite Tag Library


Posted in : Java Posted on : September 6, 2012 at 7:42 PM Comments : [ 0 ]

In this section we will learn about the JSF 2 composite tag library.

JSF 2 composite Tag Library

In this section we will learn about the JSF 2 composite tag library.

JSF 2 composite tag library facilitate you to create reusable components Facelets from the existing components. These reusable components are like a template (contains the common functionality code that is commonly required to use in the application) where the separated parts are interconnected called composite components. In a composite component, components can contain a collection of markup tags and another existing components and\or components can't or can have attached to validators, converters, listeners to do their respective actions. To create composite components you will be required to create a Facelets2 file.  And you can also convert any XHTML page with Facelets into a composite component which consists the markup tags and another existing components. You can create a composite component using the xhtml page and to made available this component to the application you must be required to create a resource library, this library will be available to the application by defining a resource location as http://java.sun.com/jsf/composite/<composite-library-name>. For example "http://java.sun.com/jsf/composite/dev/compositeComp". For this you would have first create a packaging resources in the web application root like below ( below image is given in perspective to eclipse) :

In the above directory structure image you can see the folder structure started from "resources". Here the folder name resources is mandatory and create all your composite components even a folder structure for the different composite component, inside this folder. Except the resources folder all the folder and file names are user defined. Now we will read How to create composite component ?

To create a composite components you may use the following syntax.

The Standard Syntax for creating the composite component is as follows :

<%@ taglib prefix="composite" uri="http://java.sun.com/jsf/composite" %>

And the XML Syntax for creating the composite component is as follows :

<anyxmlelement xmlns:composite="http://java.sun.com/jsf/composite" />

In both of the above syntaxes 'composite' is the prefix which means the composite tags will be used inside the pages by adding the prefix 'composite' then the tag name followed by colon. for example <composite:interface>.

To access the attributes of composite:interface following expression can be used

#{cc.attrs.attributeName}

In the above directory structure you can see there is an compositeComponent.xhtml page. Actually this is a composite component or say template that I have created to use in my application. Lets see the code description of composite component page. This is a basic description about how a composite component page can be created and what this page may contains.

<!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"

// Other JSF tag libraries XML syntaxes can written here.

xmlns:composite="http://java.sun.com/jsf/composite" > (Syntax required for creating composite component)


<composite:interface>

// Other children tag may be used here

</composite:interface>

<composite:implementation>

// Other children tag and/or existing JSF's tag library may be used here

</composite:implementation>

</html>

List of JSF composite tag library :

  • interface : This tag is used to declare the use for a composite component.
  • implementation : This tag is used to define a composite component's implementation.
  • attribute : This tag is used to declare an attribute for the composite component.
  • facet : This tag is used to specify the facet is supported by this composite component.
  • renderFacet : This tag is used to specify a facet with the attribute name.
  • insertChildren : This tag is used to insert a child within the composite component.
  • valueHolder : This tag is used for holding the value (attached objects) of the referenced composite component.
  • editableValueHolder : This tag is used to implement the EditableValueHolder.
  • actionSource : This tag is used to specify the action source for the composite component declared in composite:interface.
  • extension : This tag is used inside the composite:interface to add an XML element.
  • insertFacet : This tag is used to insert a facet child of the component by taking from the top level facet map.
Go to Topic «PreviousHomeNext»

Your Comment:


Your Name (*) :
Your Email :
Subject (*):
Your Comment (*):
  Reload Image
 
 

 
Tutorial Topics