是否可以使用 Sitemesh 直接在 JSP 中定义装饰器?
我知道我应该在配置文件或我自己的 ConfigurableSiteMeshFilter 子类中定义装饰器。例如:
public class SitemeshFilter extends ConfigurableSiteMeshFilter {
@Override
protected void applyCustomConfiguration(final SiteMeshFilterBuilder builder) {
builder.addDecoratorPath("/*", "/WEB-INF/views/layouts/default.jsp");
}
}
这对我有用,但并不完美。我可以定义直接在 JSP 文件中使用什么装饰器吗?
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<%@ page session="false" %>
<html sitemesh:decorator="layouts/default.jsp"> <!-- something like this -->
<head>
<title>Home</title>
<meta content="test" name="description" />
</head>
<body>
<h1>Hello world!</h1>
${body}
</body>
</html>
I know I should define decorators in a configuration file or my own subclass of ConfigurableSiteMeshFilter
. For example:
public class SitemeshFilter extends ConfigurableSiteMeshFilter {
@Override
protected void applyCustomConfiguration(final SiteMeshFilterBuilder builder) {
builder.addDecoratorPath("/*", "/WEB-INF/views/layouts/default.jsp");
}
}
This works for me but this isn't perfect. Can I define what decorator to use directly in a JSP file?
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<%@ page session="false" %>
<html sitemesh:decorator="layouts/default.jsp"> <!-- something like this -->
<head>
<title>Home</title>
<meta content="test" name="description" />
</head>
<body>
<h1>Hello world!</h1>
${body}
</body>
</html>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
使用元标记
我们一直这样做。
在您的 sitemesh.xml 中,允许页面位于名为decorator的元标记中,例如:
在decorators.xml中,添加一个装饰器,例如:
然后,在您的html或jsp页面中,您可以添加一个名为decorator的元标记来在之间切换您的默认模板和替代模板:
希望有帮助...
use a meta tag
We do this all the time.
In your sitemesh.xml, allow the page to be in a meta tag named decorator like:
In your decorators.xml, add a decorator like:
Then, in your html or jsp page, you can add a meta tag called decorator to switch between your default and alternative templates:
Hope that helps...