sitemesh和tiles 2.1与spring MVC集成

发布于 2024-09-02 12:02:22 字数 3865 浏览 2 评论 0原文

是否可以将sitemesh和tiles 2.1与spring mvc集成? 我想用tiles来合成布局,然后用sitemesh来装饰。

我就是用这样的瓷砖。

   <bean id="tilesConfigurer" class="org.springframework.web.servlet.view.tiles2.TilesConfigurer">
        <property name="definitions">
            <list>
                <value>/WEB-INF/layouts/layouts.xml</value>
                <value>/WEB-INF/views.xml</value>
                <value>/WEB-INF/hotels/views.xml</value>
                <value>/WEB-INF/hotels/booking/views.xml</value>
                                <value>/WEB-INF/cliente/views.xml</value>
            </list>
        </property>
    </bean>

然后我在 xml 中配置 sitemesh。

 <filter>
        <filter-name>sitemesh</filter-name>
        <filter-class>com.opensymphony.sitemesh.webapp.SiteMeshFilter</filter-class>
    </filter>
    <filter-mapping>
        <filter-name>sitemesh</filter-name>
        <url-pattern>/*</url-pattern>
    </filter-mapping>

然后我添加了装饰器

<?xml version="1.0" encoding="UTF-8"?>
<decorators defaultdir="/styles">


    <decorator page="application/themeManager/theme.jsp" name="theme">
        <pattern>/spring/hotels/index</pattern>

    </decorator>


</decorators>

但这并没有做任何事情,我认为图块避免了sitemesh来处理页面,该怎么做?

这是 sitemesh.xml 我只是使用示例附带的默认值

<sitemesh>
    <property name="decorators-file" value="/WEB-INF/decorators.xml"/>
      <excludes file="${decorators-file}"/>
    <!--<excludes file="/WEB-INF/decorators.xml"/>-->

    <page-parsers>
        <parser content-type="text/html" class="com.opensymphony.module.sitemesh.parser.HTMLPageParser" />
    </page-parsers>

    <decorator-mappers>

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

        <mapper class="com.opensymphony.module.sitemesh.mapper.FrameSetDecoratorMapper">
        </mapper>

        <mapper class="com.opensymphony.module.sitemesh.mapper.AgentDecoratorMapper">
            <param name="match.MSIE" value="ie" />
            <param name="match.Firefox" value="mozilla" />
            <param name="match.Opera" value="opera" />
            <param name="match.Lynx" value="lynx" />
        </mapper>

        <mapper class="com.opensymphony.module.sitemesh.mapper.PrintableDecoratorMapper">
            <param name="decorator" value="printable" />
            <param name="parameter.name" value="printable" />
            <param name="parameter.value" value="true" />
        </mapper>

        <mapper class="com.opensymphony.module.sitemesh.mapper.RobotDecoratorMapper">
            <param name="decorator" value="robot" />
        </mapper>

        <mapper class="com.opensymphony.module.sitemesh.mapper.ParameterDecoratorMapper">
            <param name="decorator.parameter" value="decorator" />
            <param name="parameter.name" value="confirm" />
            <param name="parameter.value" value="true" />
        </mapper>

        <mapper class="com.opensymphony.module.sitemesh.mapper.FileDecoratorMapper">
        </mapper>

        <mapper class="com.opensymphony.module.sitemesh.mapper.ConfigDecoratorMapper">
            <param name="config" value="${decorators-file}" />
        </mapper>

    </decorator-mappers>

</sitemesh>

Is posible to integrate sitemesh and tiles 2.1 with spring mvc ?
I want to composite the layout with tiles and then decorate with sitemesh.

I was using tiles like that.

   <bean id="tilesConfigurer" class="org.springframework.web.servlet.view.tiles2.TilesConfigurer">
        <property name="definitions">
            <list>
                <value>/WEB-INF/layouts/layouts.xml</value>
                <value>/WEB-INF/views.xml</value>
                <value>/WEB-INF/hotels/views.xml</value>
                <value>/WEB-INF/hotels/booking/views.xml</value>
                                <value>/WEB-INF/cliente/views.xml</value>
            </list>
        </property>
    </bean>

Then I configure sitemesh in the xml.

 <filter>
        <filter-name>sitemesh</filter-name>
        <filter-class>com.opensymphony.sitemesh.webapp.SiteMeshFilter</filter-class>
    </filter>
    <filter-mapping>
        <filter-name>sitemesh</filter-name>
        <url-pattern>/*</url-pattern>
    </filter-mapping>

And then I added decorator

<?xml version="1.0" encoding="UTF-8"?>
<decorators defaultdir="/styles">


    <decorator page="application/themeManager/theme.jsp" name="theme">
        <pattern>/spring/hotels/index</pattern>

    </decorator>


</decorators>

But this doesn't do nothing, I think that tiles avoid to sitemesh to process the page, how to do this ?

This the sitemesh.xml I just using the default that comes with the examples

<sitemesh>
    <property name="decorators-file" value="/WEB-INF/decorators.xml"/>
      <excludes file="${decorators-file}"/>
    <!--<excludes file="/WEB-INF/decorators.xml"/>-->

    <page-parsers>
        <parser content-type="text/html" class="com.opensymphony.module.sitemesh.parser.HTMLPageParser" />
    </page-parsers>

    <decorator-mappers>

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

        <mapper class="com.opensymphony.module.sitemesh.mapper.FrameSetDecoratorMapper">
        </mapper>

        <mapper class="com.opensymphony.module.sitemesh.mapper.AgentDecoratorMapper">
            <param name="match.MSIE" value="ie" />
            <param name="match.Firefox" value="mozilla" />
            <param name="match.Opera" value="opera" />
            <param name="match.Lynx" value="lynx" />
        </mapper>

        <mapper class="com.opensymphony.module.sitemesh.mapper.PrintableDecoratorMapper">
            <param name="decorator" value="printable" />
            <param name="parameter.name" value="printable" />
            <param name="parameter.value" value="true" />
        </mapper>

        <mapper class="com.opensymphony.module.sitemesh.mapper.RobotDecoratorMapper">
            <param name="decorator" value="robot" />
        </mapper>

        <mapper class="com.opensymphony.module.sitemesh.mapper.ParameterDecoratorMapper">
            <param name="decorator.parameter" value="decorator" />
            <param name="parameter.name" value="confirm" />
            <param name="parameter.value" value="true" />
        </mapper>

        <mapper class="com.opensymphony.module.sitemesh.mapper.FileDecoratorMapper">
        </mapper>

        <mapper class="com.opensymphony.module.sitemesh.mapper.ConfigDecoratorMapper">
            <param name="config" value="${decorators-file}" />
        </mapper>

    </decorator-mappers>

</sitemesh>

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

揽月 2024-09-09 12:02:22

SiteMesh 有点脆弱,您无法从中获得太多日志信息,因此确定是否确实发生了任何事情可能很棘手。

我的猜测是装饰器被绕过,因为内容类型不匹配。您的 sitemesh.xml 文件包含以下条目:

<page-parsers>
    <parser content-type="text/html" class="com.opensymphony.module.sitemesh.parser.HTMLPageParser" />
</page-parsers>

换句话说,只有当响应内容类型为 text/html 时才会调用装饰器。

您说,如果您将其指向不经过 Spring 的路径,它就会起作用,我认为这是因为 Spring 正在更改内容类型,因此绕过了装饰器。

尝试将以下附加条目添加到 sitemesh.xml 中:

<parser content-type="text/html;charset=ISO-8859-1" class="com.opensymphony.module.sitemesh.parser.HTMLPageParser" />

注意添加到内容类型中的 charset。 Spring MVC 对内容类型非常挑剔,我怀疑它正在将其更改为包含字符集的内容。如果您的本地字符集不是 ISO-8859-1,请尝试一下。您可以根据需要添加任意数量的 条目。

SiteMesh is a bit fragile, and you don't get much logging information from it, so it can be tricky to determine if anything is actually happening.

My guess is that the decorator is being bypassed because the content-type doesn't match. Your sitemesh.xml file contains the following entry:

<page-parsers>
    <parser content-type="text/html" class="com.opensymphony.module.sitemesh.parser.HTMLPageParser" />
</page-parsers>

In other words, the decorator will only be invoked if the response content-type is text/html.

You said that it works if you point it at a path that does not go through Spring, and I think that's because Spring is changing the content-type, and is therefore bypassing the decorator.

Try adding the following additional entry to sitemesh.xml:

<parser content-type="text/html;charset=ISO-8859-1" class="com.opensymphony.module.sitemesh.parser.HTMLPageParser" />

Note the charset added to the content-type. Spring MVC is pretty fastideous with content-types, and I suspect it's changing it to something that includes the charset. If your local charset is something other than ISO-8859-1, then try that. You can add as many <parser> entries as you like.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文