Using Static Includes for Pages with JSF Components

Static includes for JSP pages containing JSF component actions work the same as for regular JSP pages. I use static includes to piece together the sample application, because the main reason for splitting it up in the first place is maintainability. All filenames are known at development time and using static includes avoid the runtime penalty and other issues, as described earlier.

Example 12-1 shows the top level JSP page, i.e., the one the pulls in all the other ones.

Example 12-1. The top-level page for the sample application (expense/final/reports.jsp)
<%@ page contentType="text/html" %>
<%@ taglib uri="http://java.sun.com/jsf/html" prefix="h" %>
<%@ taglib uri="http://java.sun.com/jsf/core" prefix="f" %>
<%@ taglib uri="http://mycompany.com/jsftaglib" prefix="my" %>

<html>
  <head>
    <title>Expense Reports</title>
    <link rel="stylesheet" type="text/css" 
                        href="${pageContext.request.contextPath}/style.css">
  </head>
  <body bgcolor="white">
    <f:view locale="#{userProfile.locale}">
                        <f:loadBundle basename="labels" var="labels" />
      <table width="95%" align="center">
        <tr>
          <td colspan="2">
            <!-- Title -->
            <h:outputText value="#{labels.applicationTitle}" 
              styleClass="title" />
          </td>
        </tr>
        <tr>
          <td colspan="2" class="toolbar">
            <!-- Menu -->
            <h:form>
                                <%@ include file="menuArea.jspf" %>
                              </h:form>
          </td>
        </tr>
        <tr>
          <td valign="top" width="60%">
            <!-- Reports -->
            <h:form>
                                <%@ include file="reportsArea.jspf" %>
                              </h:form> </td> <td valign="top"> ...

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.