ConfigurableSiteMeshFilter

ConfigurableSiteMeshFilter

本文介绍了是否可以使用Sitemesh直接在JSP中定义装饰器?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

限时删除!!

我知道我应该在配置文件或我自己的 ConfigurableSiteMeshFilter 的子类中定义装饰器。例如:

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");
    }
}

这对我有用,但这并不完美。我可以直接在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>


推荐答案

使用元标记

我们一直这样做。

在您的sitemesh.xml中,允许该页面位于名为decorator的元标记中,如:

In your sitemesh.xml, allow the page to be in a meta tag named decorator like:

   <decorator-mappers>
      <mapper class="com.opensymphony.module.sitemesh.mapper.PageDecoratorMapper">
         <param name="property.1" value="meta.decorator"/>
         <param name="property.2" value="decorator" />
      </mapper>
  </decorator-mappers>

在decorators.xml中,添加一个装饰器,如:

In your decorators.xml, add a decorator like:

<decorators>
   <decorator name="default" page="/WEB-INF/decorators/default.jsp" />
   <decorator name="alternative" page="/WEB-INF/decorators/alternative.jsp" />
<decorators>

然后,在你的html或jsp页面中,你可以添加一个名为decorator的元标记来切换你的默认和替代模板:

Then, in your html or jsp page, you can add a meta tag called decorator to switch between your default and alternative templates:

<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<%@ page session="false" %>
<html>
    <head>
        <meta name="decorator" content="alternative" />
        <title>Home</title>
        <meta content="test" name="description" />
    </head>
    <body>
        <h1>Hello world!</h1>
        ${body}
    </body>
</html>

希望有帮助......

Hope that helps...

这篇关于是否可以使用Sitemesh直接在JSP中定义装饰器?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

1403页,肝出来的..

09-07 00:42