私はApache-Tilesを初めて使用します。実際、これを使用している最大の理由は、Spring Roo アプリケーションを作成するときのデフォルトのレンダラーだからです。私はそれが大きな支持者を持っていることを知っているので、私はそれを試してみようと思いました.
しかし、単純なタスクを達成する方法は非常に混乱しています。<head>
レイアウト内からページのセクションにいくつかの宣言を追加しようとしています。ヘッダー インクルード用とボディ インクルード用に別の jsp ページを作成し、views.xml ファイルで指定できることはわかっていますが (この SO 投稿で指摘されているように)、これは非常に扱いにくく、適切ではないようです。
たとえば、特定のビューでは、いくつかの追加の JS ライブラリを含めたいと考えています。また、ページで実行したい jQuery JS スクリプトをいくつか追加する必要があります。慣例により、私<body>
はそのようなコードを明確に保ち、すべての JS を<head>
セクションに入れます。
ただし、ビューごとに 2 つのファイル (head.jsp と body.jsp) を作成する必要があるのは適切ではないようです。結局、これは、ボディのどの要素が操作されているかなどを正確に確認するために JS jQuery コードを作成しているため、2 つのファイル (ヘッドとボディ) を開く必要があることを意味します。
Sitemesh では、同じページ内でこれを簡単に達成できることを知っています。また、Sitemesh と Tiles が同じことを行うことを意図していないことも知っていますが、2 つの個別のファイルよりも簡単にこれを行う方法があると期待していました。
(Sitemesh のように) 同じビュー JSP 内から異なるリージョン/インクルードを定義する方法はありませんか? ヘッダー用とボディ用の 2 つの異なるファイルを持つ唯一の選択肢はありますか? index.jspx ページに と defns の両方を含めることができるようにできることはありますか?
現在の設定は次のとおりです。
デフォルト.jspx:
<html xmlns:jsp="http://java.sun.com/JSP/Page" xmlns:c="http://java.sun.com/jsp/jstl/core" xmlns:tiles="http://tiles.apache.org/tags-tiles" xmlns:spring="http://www.springframework.org/tags" xmlns:util="urn:jsptagdir:/WEB-INF/tags/util" >
<jsp:output doctype-root-element="HTML" doctype-system="about:legacy-compat" />
<jsp:directive.page contentType="text/html;charset=UTF-8" />
<jsp:directive.page pageEncoding="UTF-8" />
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<meta http-equiv="X-UA-Compatible" content="IE=8" />
<util:load-scripts />
<spring:message code="application_name" var="app_name" htmlEscape="false"/>
<title><spring:message code="welcome_h3" arguments="${app_name}" /></title>
</head>
<body class="tundra spring">
<div id="wrapper">
<tiles:insertAttribute name="header" ignore="true" />
<tiles:insertAttribute name="menu" ignore="true" />
<div id="main">
<tiles:insertAttribute name="body"/>
<tiles:insertAttribute name="footer" ignore="true"/>
</div>
</div>
</body>
</html>
Views.xml:
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<!DOCTYPE tiles-definitions PUBLIC "-//Apache Software Foundation//DTD Tiles Configuration 2.1//EN" "http://tiles.apache.org/dtds/tiles-config_2_1.dtd">
<tiles-definitions>
<definition extends="default" name="rates/index">
<put-attribute name="body" value="/WEB-INF/views/rates/index.jspx" />
</definition>
</tiles-definitions>
インデックス.jspx:
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<div xmlns:jsp="http://java.sun.com/JSP/Page"
xmlns:spring="http://www.springframework.org/tags"
xmlns:util="urn:jsptagdir:/WEB-INF/tags/util"
xmlns:jQWidgets="urn:jsptagdir:/WEB-INF/tags/jQWidgets"
version="2.0">
<jsp:directive.page contentType="text/html;charset=UTF-8"/>
<jsp:output omit-xml-declaration="yes"/>
<spring:message code="label_rates_index" htmlEscape="false" var="title"/>
<util:panel id="title" title="${title}">
<spring:message code="application_name" htmlEscape="false" var="app_name"/>
<h3>
<spring:message arguments="${app_name}" code="welcome_titlepane"/>
</h3>
</util:panel>
</div>