Templates are a mechanism for laying out common page features. They are demonstrated in the planets example which can be run here.

The planets example uses a shared page layout that is used by all of its web pages. The layout defines four named variant features. Individual web pages can plug in different content for these features:

In the layout template, some of the features define a default content. This is useful when many of the web pages use the same content in a feature.

Layout templates are implemented with four tags:

To use these tags you must add the following attribute to your html tag:

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

The layout template for the planets application is defined in masterLayout.xhtml. This is an ordinary XHTML file except for the ui:insert tags:

Web Pages/templates/masterLayout.xhtml

Use ui:composition as in login.xhtml below to make use of a template:

Since ui:composition uses a master layout page that already has html, head, title, and body tags, Facelets removes all tags outside the ui:composition tag, explaining why the title is IGNORED.

Web Pages/login.xhtml

Web Pages/sections/login/titlebar.xhtml

Web Pages/planetarium.xhtml

Web Pages/saturn.xhtml

To use these tags you must add the following attribute to your html tag:

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