Combining JSF Views with Other Content

In the previous section, I described how to build a JSF view from multiple JSP pages, but sometimes you need to combine the content generated by a JSF view with content generated by other technologies, such as regular JSP pages and static HTML files.

Most web sites use a common layout for all pages, typically with a header at the top, a menu to the left, and footer at the bottom. To simplify maintenance and make it easy to change the site’s look, large sites often use tools that pull together each page based on a layout template at runtime. For JSP-based sites, a tool called Tiles is commonly used. Tiles is distributed as part of Apache Struts,[1] but it can also be used independently. Tiles has a lot of features, but the main principle is pretty simple: each page directly requested by the user calls on a layout template to generate the response from the data the page tells the template to use. Example 12-7 shows a simple Tiles layout template.

Example 12-7. Tiles layout template (tilesLayout.jsp)
               <%@ taglib uri="http://jakarta.apache.org/struts/tags-tiles" prefix="tiles" %>
<html>
  <body bgcolor="white">
    <table width="100%">
      <tr>
        <td colspan="2" align="center">
          <tiles:insert attribute="header" />
        </td>
      </tr>
      <tr>
        <td width="20%">
          <tiles:insert attribute="menu" />
        </td>
        <td>
          <tiles:insert attribute="body" />
        </td>
        <td>
          <tiles:insert page="poll.jsp" />
        </td>
      </tr>
    </table>
  </body>
</html>

The template is a JSP page. At the top, there’s a taglib ...

Get JavaServer Faces now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.