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.
<%@ 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 ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access