JSF Templating Notes and Examples.

Notes from JavaServer Faces 2.0, The Complete Reference.

Facelets Tags: xmlns:ui="http://java.sun.com/jsf/facelets"

ui:include
Includes content from another XML file.
ui:insert name="..."
Creates the places of the template file which will be used by files using this template.
ui:composition template:"..."
Makes a file use the given template. Any surrounding text in the file is ignored.
ui:define name:"..."
Replaces the "insert" places in the template file being used.

Example
template.xhtml
<html xmlns="http://www.w3.org/1999/xhtml"
      xmlns:f="http://xmlns.jcp.org/jsf/core"
      xmlns:h="http://xmlns.jcp.org/jsf/html"
      xmlns:ui="http://java.sun.com/jsf/facelets">
 
<f:view>
    <h:head>
        <title><ui:insert name="title">Default Title!</ui:insert></title>
    </h:head>
    <h:body>
        <h:graphicImage name="img/banner.png" />
    </h:body>
</f:view>
</html>

index.html
<ui:composition
        xmlns:f="http://xmlns.jcp.org/jsf/core"
        xmlns:h="http://xmlns.jcp.org/jsf/html"
        xmlns:ui="http://java.sun.com/jsf/facelets"
        template="WEB-INF/templates/template.xhtml">
    <ui:define name="title">Welcome to Registiration Page!</ui:define>
</ui:composition>
ui:decorate template=".."
Almost same with ui:composition, but surrounding text is not ignored. This enables taking any element in the page and applying it to a template. This tag is useful if you want same "look and feel" several times in a page.
ui:param name=".." vale=".."
Used inside of ui:include or ui:decorate tags.

Example
box.xhtml
<ui:composition
        xmlns="http://www.w3.org/1999/xhtml"
        xmlns:h="http://java.sun.com/jsf/html"
        xmlns:ui="http://java.sun.com/jsf/facelets">
    <div class="#{type}">
        <h:outputText value="#{warningMessage}" />
    </div>
</ui:composition>

clientpage.xhtml
<h:graphicImage name="img/banner.png"/>
<ui:decorate template="/WEB-INF/templates/box.xhtml">
    <ui:param name="type" value="warning" />
    <ui:param name="warningMessage" value="You are in trouble!!!" />
</ui:decorate>
<ui:decorate template="/WEB-INF/templates/box.xhtml">
    <ui:param name="type" value="success" />
    <ui:param name="warningMessage" value="Everything is fine!!!" />
</ui:decorate>