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

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

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