Facelet composition Tag

This is a templating tag and is used for the wrapping the content that can be included in any other facelet. This tag provides some useful features.

Facelet composition Tag

Facelet composition Tag

        

This is a templating tag and is used for the wrapping the content that can be included in any other facelet. This tag provides some useful features. Any content outside of this tag is left to be rendered. You can  include normal html content  in your page but Facelet will render only content that is within this tag i.e. composition tag. This tag takes one attribute named "template". This attribute is set to the path of the template where the content of this tag will be included. 

Code Description : 

composition.xhtml :
In the code below we have taken template attribute which indicates the template to which the content inside this composition tag will be rendered. Here we have written some content outside of the composition tag, that content will not be rendered. In the comptemplate.xhtml we have used insert tag to include the content inside the composition tag to the comptemplate.xhtml page.

<!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:ui="http://java.sun.com/jsf/facelets">
   <body>
  Content above composition tag will not be rendered.
  <ui:composition template="/pages/composition/comptemplate.xhtml">
   <h2>This is the content to be included in the comptemplate.xhtml page.</h2>
  </ui:composition>
  Content below composition tag will not be rendered.
   </body>
</html>

 comptemplate.xhtml :

<!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:ui="http://java.sun.com/jsf/facelets">
  <head>
  <title>facelet example </title>
  <link href="../../style/CSS.css" rel="stylesheet" type="text/css"/>
  </head>
  <body> 
  <ui:insert />
  </body>
</html>

 Rendered Output :

Html Source Code :

<!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">
   <head>
   <title>facelet example </title>
  <link href="../../style/CSS.css" rel="stylesheet" type="text/css" />
  </head>
  <body>
   <h2>This is the content to be included in the comptemplate.xhtml page.</h2>
  </body>
</html>

 This tag contains only one attribute :

template : This attribute is set to the template where the content inside this tag will be included.