Overview | Package | Class | Tree | Deprecated | Index | Help
PREV PACKAGE NEXT PACKAGE | FRAMES NO FRAMES

## Package org.apache.struts.taglib.template

The "struts-template" tag library contains tags that are useful in creating dynamic JSP templates for pages which share a common format.

See:
Description

Class Summary
GetTag | This is the tag handler for <template:get>, which gets content from the request scope and either includes the content or prints it, depending upon the value of the content's direct attribute.
InsertTag | This is the tag handler for <template:insert>, which includes a template.
PutTag | Tag handler for <template:put>, which puts content into request scope.

## Package org.apache.struts.taglib.template Description

The "struts-template" tag library contains tags that are useful in creating dynamic JSP templates for pages which share a common format. These templates are best used when it is likely that a layout shared by several pages in your application will change. The functionality provided by these tags is similar to what can be achieved using standard JSP include directive, but are dynamic rather than static.

[Introduction] [Template Functionality] [Template Properties] [Template Examples]

### Introduction

The Template library supplies tags that are useful for creating dynamic JSP templates for pages which share a common format.

### Template Tag Functionality

Each of the three template tags has a specific, interelated function:

- get - Retrieves content from a request scope bean, for use in the template layout.
- insert - Retrieves (or includes) the specified template file, and then inserts the specified content into the template's layout. By changing the layout defined in the template file, any other file that inserts the template will automatically use the new layout.
- put - Creates a request scope bean that specifies the content to be used by the get tag. Content can be printed directly or included from a JSP or HTML file.

### Template Tag Properties

The three template tags use very simple attributes :

> get - Requires a single property, the name of the content to be inserted. This tag is used in the template file to indicate where in the layout to insert the content. This name matches the name property used by a put tag.

> insert - Requires a single property, the name of the template. This tag is the parent to one or more put tags. The put tags indicate the content to be inserted into the template. The layout of the content is determined by get tags placed in the template.

> put - Requires a name property, which should match a name used in the template file. The content property indicates the source of the content. The optional direct attribute indicates whether the content should be included or printed directly (as a literal string). The default is false, meaning content is included.

> ### Template Tag Examples

> A sample template file

> >     <%@ taglib uri='/WEB-INF/tlds/struts-template.tld' prefix='template' %>
> >     <html><head><title><template:get name='title'/></title></head>
> >     <body background='graphics/blueAndWhiteBackground.gif'>
> >     <table>
> >       <tr valign='top'><td><template:get name='sidebar'/></td>
> >           <td><table>
> >                 <tr><td><template:get name='header'/></td></tr>
> >                 <tr><td><template:get name='content'/></td></tr>
> >                 <tr><td><template:get name='footer'/></td></tr>
> >               </table>
> >           </td>
> >        </tr>
> >     </table>
> >     </body></html>
> >     <%
> >     /*
> >     "chapterTemplate.jsp"
> >     Display a "sidebar" in a column along the left side of the page.
> >     Display a "header" over the right column.
> >     Display the page "content" below the header.
> >     Display a "footer" at below the content.
> >     If we change the layout of the elements on this page, all pages
> >     inserting this page will also change to use the new layout.
> >     */
> >     %>

> A sample JSP using the template

> >     <%@ taglib uri='/WEB-INF/tlds/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' />
> >     </template:insert>
> >     <%
> >     /*
> >     "introduction.jsp"
> >     Specify template for this page (chapterTemplate.jsp).
> >     The chapterTemplate.jsp defines the layout positions for five
> >     elements: title, header, sidebar, content, and footer.
> >     Specify the source file (html or jsp) for each element.
> >     */
> >     %>

> A sample HTML content file ("header.html") used by "introduction.jsp", and others.

> >     <table>
> >     <tr>
> >     <td><img src='graphics/java.gif'/></td>
> >     <td><img src='graphics/templates.gif'/></td>
> >     </tr>
> >     </table>

> A sample JSP content file ("sidebar.jsp") used by "introduction.jsp", and others.

> >     <font size='5'><a name="top">Topics</a></font><p>
> >     <table width='145'>
> >         <tr><td><a href='introduction.jsp'>
> >             Introduction </a></td></tr>

> >         <tr><td><a href='using.jsp'>
> >             Using Templates </a></td></tr>

> >         <tr><td><a href='optional.jsp'>
> >             Optional Content </a></td></tr>
> >         <tr><td><a href='more.jsp'>
> >             ... and more ...</a></td></tr>
> >       </table></p>

> >     <%
> >     /*
> >     Specify navigational links for this application.
> >     */
> >     %>

> A sample HTML content file used by "introduction.jsp" only.

> >     <html>
> >     <head>
> >     <link rel="stylesheet" href="css/templates.css"
> >     charset="ISO-8859-1" type="text/css">
> >     </head>
> >     <body>
> >     <h3 class="ChapTitle">Introduction</h3>
> >     <p class="Paragraph">Window toolkits typically provide a layout mechanism
> >     < ... />

> Overview | Package | Class | Tree | Deprecated | Index | Help
> PREV PACKAGE NEXT PACKAGE | FRAMES NO FRAMES

> Copyright © 2000-2001 - Apache Software Foundation