O'Reilly logo

JavaServer Faces by Hans Bergsten

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

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 ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required