0 Replies Latest reply on Jan 9, 2002 11:24 PM by Tom McFadden

    Problem with Struts 1.0 templates and JBOSS_2-4-4-and-Jetty_

    Tom McFadden Newbie

      The struts 1.0 template example doesn't appear to work properly with Jetty. The template page follows the inserts. See the resulting HTML source for more information. Your insights are appreciated on this problem.

      E-Mail: tmcfadd1@rochester.rr.com

      HTML Source



      Using Templates

      Optional Content

      ... and more ...

      This example application is based on Using JSP templates to encapsulate Webpage layout and encourage modular design by David Geary. Follow that link for the full article, which also covers using role-based and nested templates. The template classes described in the Java World article were the basis for those included with Struts 1.0.
      <h3 class="ChapTitle">Introduction</h3>
      Window toolkits typically provide a layout mechanism that positions widgets in a container; for example, AWT and Swing have layout managers, whereas VisualWorks Smalltalk has wrappers.
      Because layout undergoes many changes over the course of development, it's important to encapsulate that functionality so layout can be modified with minimal impact to the rest of the application. In fact, layout managers are an example of one of the tenets of object-oriented design: encapsulate the concept that varies, which is also a fundamental theme for many design patterns.
      JSP does not provide direct support for encapsulating layout, so web pages with identical formats usually replicate layout code; for example, A Web Page Layout shows a web page containing sections for a header, footer, sidebar, and main content.
      The layout of the page shown in A Web Page Layout is implemented with HTML table tags, as listed in Including Content.

      <h4 class="CodeCaption">Including Content</h4>


      <jsp:include page='sidebar.jsp'/>

      <jsp:include page='header.html'/>
      <jsp:include page='chapter.jsp'/>
      <jsp:include page='footer.jsp'/>


      In Including Content, content is included with <jsp:include> which allows content to vary without modifying HTML; however, because the layout is hardcoded, layout changes require modifications to the page. If a website has many pages with identical formats, even simple layout changes require modifications to all of the pages.
      <h4 class="ChapTitle">Using A Template</h4>

      <%@ taglib URI='/WEB-INF/struts-template.tld' prefix='template' %>

      <template:insert template='/chapterTemplate.jsp'>
      <template:put name='title' content='Templates' direct='true'/>
      <template:put name='header' content='/header.html'/>
      <template:put name='sidebar' content='/sidebar.jsp'/>
      <template:put name='content' content='/introduction.html'/>
      <template:put name='footer' content='/footer.html'/>

      To minimize the impact of layout changes, a mechanism is needed for dynamically including layout in addition to content. That way, both layout and content can be changed without modifying files that use them. For large websites that have many pages with identical formats, such a mechanism is valuable because it localizes changes to layout. That mechanism is JSP templates.