Sitemesh and tiles 2.1 integration with spring MVC
Is it possible to integrate sitemesh and slabs 2.1 using spring mvc? I want to combine the layout with tiles and then decorate the sitemesh.
I've used tiles like this.
<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 set up the 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 a 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 that doesn't do anything, I think the tiles are escaping the sitemesh to render the page, how to do this?
This is the default sitemesh.xml file that comes with 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>
a source to share
SiteMesh is a little flimsy and you don't get a lot of registration information from it, so it can be tricky to determine if something is really going on.
I'm guessing the decorator is getting around because the content type doesn't match. Your file sitemesh.xml
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 called if the content type is the response text/html
.
You said it works if you point it in a path that doesn't go through Spring, and I think that since Spring changes the content type and thus bypasses 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" />
Notice the charset
added content type. Spring MVC is pretty fast with content types and I suspect it is changing it to something that includes the encoding. If your local encoding is something other than ISO-8859-1
try this. You can add as many entries <parser>
as you like.
a source to share