Templating in JSF 2

Templating in JSF 2


Posted in : Java Posted on : October 3, 2012 at 5:08 PM Comments : [ 0 ]

In this section we will learn about how templating can be done in JSF with Facelets.

Templating in JSF 2

In this section we will learn about how templating can be done in JSF with Facelets.

Templating, is a view composition technique in JSF that provides the facility to encapsulate and reuse the single page to the multiple pages (if required) in a web application. For example Such as The 'Tiles' framework, 'SiteMesh' etc. are used for templating. Generally in most of the web applications you will have seen that the multiple of web pages containing the similar layout and styling like the header, footer part of web pages. These pages are not created each time, for this a layout is created and reused every time. Different technologies uses different templating features. Templating is most important feature required for the web application development for that there are the complete frameworks. The JavaServer Faces 2 lets add the templating feature using the JSF 2 ui tag library. This tag library has the many tags (described later) that participates in templating.

Syntaxes to use the JSF 2 ui tag library

Standard Syntax

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

XML Syntax

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

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

Tags of JSF 2 ui tag library

  • composition : This tag is used to specify a composition that may use a template. Contents outside of this tag is disregarded.
  • component : Similar to ui composition tag which is used to create component.
  • debug : This tag is used to create a debug component that that keep records of debugging information.
  • define : This tag is used to define the contents which is inserted into a page through template.
  • decorate : This tag is exactly alike the ui:composition tag except disregarding the contents outside of tag.
  • fragment : This tag is exactly alike the ui:component tag except disregarding the contents outside of tag.
  • include : This tag is used to include the xhtml pages.
  • insert : This tag is used to insert content, defined by the ui:define tag, into a template.
  • param : This tag is used to provide the value to the template or an included file as a parameter.
  • repeat : This tag is used as an alternate to h:dataTable or c:forEach tag.
  • remove : This tag is used to remove content from a page.

 

Go to Topic «PreviousHomeNext»

Your Comment:


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

 
Tutorial Topics