给出一个由Sitemesh 3呈现的简单的JSP模板:
<%@include file="../jsp_inc/taglibs.jsp" %>
<!DOCTYPE html>
<head>
<link rel="stylesheet" type="text/css" href='<c:url value="/css/global.css" />' >
</head>
<body>
<h1>[HEADING]</h1>
<div>
<sitemesh:write property='body'/>
</div>
</body>该模板按照预期工作,将JSP元素的内容插入到模板中。
正如您从上面所期望的那样,我希望能够在JSP中插入一个值集(例如,h1元素)添加到我的模板中的相应元素。
我试过了:
<sitemesh:getProperty property="page.heading"></sitemesh:getProperty>在模板/装饰器中:
<content tag="heading"></content>在JSP中,根据关于SO的另一个问题,我认为这可能是指Sitemesh 2。我使用的是Sitemesh 3。
有什么建议吗?
发布于 2013-06-07 13:49:01
不确定你是否还在使用Sitemesh 3,但我正在检查它,在浏览源代码后发现你已经配置了构建器。
我使用Java based configuration并创建了自己的子类,它添加了一个支持Sitemesh 2样式内容块的标记处理规则包:
public class MySiteMeshFilter extends ConfigurableSiteMeshFilter {
@Override
protected void applyCustomConfiguration(SiteMeshFilterBuilder builder) {
builder.addTagRuleBundle(new Sm2TagRuleBundle());
}
}通过sitemesh3.xml中的XML配置:
<sitemesh>
<content-processor>
<tag-rule-bundle class="org.sitemesh.content.tagrules.html.Sm2TagRuleBundle" />
</content-processor>
<!-- Your mappings go here -->
<mapping ... />
</sitemesh>这样做可以让您使用如下内容标签:
<content tag="heading"></content>在装饰器/模板页面中,使用sitemesh:write标记而不是不再存在的sitemesh:getProperty:
<sitemesh:write property="page.heading"/>https://stackoverflow.com/questions/15441352
复制相似问题