Question

I have consult Sitemesh does not decorate returned views, but this post does not work for me.

I hope sitemesh only decorate .jsp pages, but when one view is returned by a controller, it is not decorated.

This is part of my web.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>

This is my decorators.xml:

<?xml version="1.0" encoding="UTF-8"?>    
<decorators>
    <decorator name="basicLayout" page="/WEB-INF/decorators/base_layout.jsp">
        <pattern>*.jsp</pattern>
    </decorator>
</decorators>

I use InternalResourceViewResolver to resolve my view from logic name to actual path:

<bean class="org.springframework.web.servlet.view.InternalResourceViewResolver"
    p:viewClass="org.springframework.web.servlet.view.JstlView"
    p:prefix="/WEB-INF/jsp/"
    p:suffix=".jsp" />

And this is my Controller:

@Controller
public class UserController {
    @RequestMapping("/user/registration")
    public String registrationForm() {
        return "user/registration";
    }   
}

My jsp page is /WEB-INF/jsp/user/registration.jsp. After I request user/registration, that jsp page comes without any decoration.

Was it helpful?

Solution

Change your pattern to

<pattern>/*</pattern>

The path in the pattern is matched again the request path, not the internal RequestDispatcher#forward() done with the view name by the InternalResourceViewResolver.

You can make your SiteMeshFilter only work on forward requests though, with

<filter-mapping>
    <filter-name>sitemesh</filter-name>
    <url-pattern>/*</url-pattern>
    <dispatcher>FORWARD</dispatcher>
</filter-mapping>
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top