I'm migrating a set of grails 2.0.4 applications to version 3.x. All of them are deployed in the same server together with a number of java applications. Both sets of java and grails applications have a common look and feel using sitemesh and freemarker templates. But with grails 3.x I can't make the commond decoration work, the application insists in using layouts/main.gsp to render my gsp instead.
So far (grails 2.0.4) providing a common decoration is rather straight; the file /WEB-INF/decorators.xml of each grails application provides with references to the applicable freemarker templates. And the web.xml includes the sitemesh filter and the freemarker decorator servlet declarations and mappings
decorators.xml:
<?xml version="1.0" encoding="UTF-8"?>
<decorators defaultdir="/">
<excludes>
<pattern>/ND/*</pattern>
<pattern>/*/ND/*</pattern>
</excludes>
<decorator name="freemarker" page="myftl.ftl">
<pattern>/*</pattern>
</decorator>
</decorators>
Sitemesh filter and freemarker servlet from web.xml:
<filter>
<filter-name>sitemesh</filter-name>
<filter-class>org.codehaus.groovy.grails.web.sitemesh.GrailsPageFilter</filter-class>
</filter>
<filter-mapping>
<filter-name>sitemesh</filter-name>
<url-pattern>/*</url-pattern>
<dispatcher>REQUEST</dispatcher>
<dispatcher>ERROR</dispatcher>
</filter-mapping>
<servlet>
<servlet-name>sitemesh-freemarker</servlet-name>
<servlet-class>com.opensymphony.module.sitemesh.freemarker.FreemarkerDecoratorServlet</servlet-class>
<init-param>
<param-name>TemplatePath</param-name>
<param-value>class://</param-value>
</init-param>
<init-param>
<param-name>default_encoding</param-name>
<param-value>UTF-8</param-value>
</init-param>
<load-on-startup>2</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>sitemesh-freemarker</servlet-name>
<url-pattern>*.ftl</url-pattern>
</servlet-mapping>
What I've tried:
- I've moved the decorators.xml under src/main/webapp/WEB-INF
- In grails 3.x sitemesh filter is not present anymore and so, I've removed sitemesh.xml
- web.xml is not used, so now I've defined the freemarker servlet at spring/resources.groovy:
resources.groovy:
beans = {
sitemeshFreemarkerServlet(ServletRegistrationBean) {
servlet = bean(FreemarkerDecoratorServlet)
urlMappings = ["*.ftl"]
loadOnStartup = 2
}
}
However, the grails 3.x applications insists in using layouts/main.gsp to render my gsp pages. It seems that decorators.xml is not being processed. What am I missing?