パッケージ org.apache.struts.taglib.template

"struts-template" タグライブラリには、複数のページがひとつのフォーマットを共有することを目的とした、 動的に適用される JSP のテンプレートを作成するのに有用なタグが含まれています。

参照:
          説明

クラスの概要
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.
 

パッケージ org.apache.struts.taglib.template の説明

"struts-template" タグライブラリには、複数のページがひとつのフォーマットを共有することを目的とした、 動的に適用される JSP のテンプレートを作成するのに有用なタグが含まれています。 これらのテンプレートは、アプリケーション中のいくつかのページから共有されるレイアウトに変更がある場合に最も有効です。 これらのタグによって提供される機能は、標準の JSP の include ディレクティブを使用して達成できることに似ていますが、 静的というよりはむしろ動的なものとなっています。

[イントロダクション] [テンプレート機能] [テンプレートプロパティ] [テンプレート例]


イントロダクション

Template ライブラリは、複数のページがひとつのフォーマットを共有することを目的とした、 動的に適用される JSP のテンプレートを作成するのに有用なタグを提供しています。

Template タグの機能

3つのテンプレートタグはそれぞれ決まった、相互に関連付いた機能を持ちます :

テンプレートタグのプロパティ

これら3つのテンプレートタグは非常にシンプルな属性を用います :

get - 単一のプロパティ ( 挿入されるコンテンツの名前 ) を必要とします。 このタグは、コンテンツをレイアウトのどこに挿入するかを示すテンプレートファイルで使用されます。 このプロパティの値は put タグで使用される name プロパティと合致します。

insert - 単一のプロパティ ( テンプレートの名前 ) を必要とします。 このタグは一つまたは複数の put タグの親タグになり、put タグは、テンプレートに挿入されるコンテンツを示します。 コンテンツのレイアウトはテンプレートに配置された get タグによって決定されます。

put - name プロパティを必要とします。 これはテンプレートファイルで使われる名前に合致しなければなりません。 content プロパティは、コンテンツのソースを示します。 オプションの direct 属性は、コンテンツがインクルードされなければならないか、 文字列リテラルとして直接記述されなければならないかを示します。 デフォルトでは falseで、コンテンツがインクルードされることを意味します。

Template タグの例

テンプレートファイルの例


<%@ 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" "sidebar"をページ左側カラムに表示します。
"header"を右側のカラムに表示します。
"content"を header の下に表示します。
"footer"を content の下に表示します。
このページの要素のレイアウトを変更する場合、このページを挿入している
全てのページにも新しいレイアウトが使用されます。
*/
%>

テンプレートを利用した JSP の例


<%@ 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" このページのテンプレートを指定します ( chapterTemplate.jsp ) 。
chapterTemplate.jsp は title, header, sidebar,
content, footer の5つの要素のレイアウト位置を指定し、
それぞれの要素のソースファイル ( html または jsp ) を指定します。
*/
%>

"introduction.jsp" などに使用される HTML コンテンツファイルの例 ( "header.html" )


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

"introduction.jsp" などに使用される JSP の例 ( "sidebar.jsp" )


<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>
<%
/* このアプリケーションのナビゲーションリンクを指定します。
*/
%>

"introduction.jsp" だけに使用される HTML コンテンツファイルの例


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

[訳注: これは岩崎浩文、おかだひでひさ が翻訳しました。日本語訳に対するコメントがあれば、report@jajakarta.orgに送って下さい。]



このドキュメントは、Ja-Jakartaにより訳されました。コメントがある場合は、report@jajakarta.orgまでお願いします。
Copyright (C) 2000-2002 - Apache Software Foundation