Spring 在Apache Tiles布局中指定唯一的内容
我对ApacheTiles不熟悉。事实上,我使用它的最大原因是,它是创建SpringRoo应用程序时的默认渲染器。我知道它有很多追随者,所以我想我会试试看 然而,我很困惑如何完成一项简单的任务。我希望从我的布局中向页面的部分添加一些声明。我知道/意识到我可以为header include创建一个单独的jsp页面,为body include创建一个单独的jsp页面,并在我的views.xml文件中指定它们,但这看起来非常笨拙,不合适 例如,在specify视图中,我想包括一些附加的JS库。另外,我需要添加一些我想在页面上运行的jqueryjs脚本。按照惯例,我喜欢避开任何此类代码,并将所有JS放在该部分中 但是,需要为每个视图创建两个文件(head.jsp和body.jsp)似乎并不正确。毕竟,这意味着在编写JS jQuery代码时,我需要打开头部和身体两个文件,以查看身体中的哪些元素正在被操作,等等 我知道在Sitemesh中,我可以在同一页面内轻松完成这一任务。我也知道Sitemesh和Tiles并不打算做同样的事情,但我希望有一种比两个单独的文件更容易做到这一点的方法 是否无法从与Sitemesh相同的jsp视图中定义不同的区域/包含?唯一的选择是有两个不同的文件-一个用于标题,一个用于正文?我是否无法在index.jspx页面中同时使用和defns 当前设置为: Default.jspx:Spring 在Apache Tiles布局中指定唯一的内容,spring,jsp,apache-tiles,Spring,Jsp,Apache Tiles,我对ApacheTiles不熟悉。事实上,我使用它的最大原因是,它是创建SpringRoo应用程序时的默认渲染器。我知道它有很多追随者,所以我想我会试试看 然而,我很困惑如何完成一项简单的任务。我希望从我的布局中向页面的部分添加一些声明。我知道/意识到我可以为header include创建一个单独的jsp页面,为body include创建一个单独的jsp页面,并在我的views.xml文件中指定它们,但这看起来非常笨拙,不合适 例如,在specify视图中,我想包括一些附加的JS库。另外,我
<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>
Index.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>
使用瓷砖时,您使用的是复合图案,而不是使用Sitemesh时使用的装饰图案 Tiles功能强大且非常灵活,您可以选择从字符串属性、列表属性到通配符的多个选项。查看Tiles文档 另一篇介绍Tiles更高级功能的博客文章在