Package org.apache.struts.taglib.template

Note: As of Struts 1.1 the template tag library is deprecated in favor of Tiles.

See:
          Description

Class Summary
GetTag Deprecated. Use Tiles instead.
InsertTag Deprecated. Use Tiles instead.
PutTag Deprecated. Use Tiles instead.
 

Package org.apache.struts.taglib.template Description

Note: As of Struts 1.1 the template tag library is deprecated in favor of Tiles.

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 UML] [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:

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



Copyright © 2000-2003 - Apache Software Foundation