Search code examples
javaxmlspring-mvcsitemesh

Spring 4 + Sitemesh with Java Config and no xml


I'm building Spring 4 MVC application. I've already integrated sitemesh with my project... however, I'm trying to prepare XML free configuration - I do not have web.xml file and of course I would like to move my decorator confiration into Java Config classes. Is it possible to configure my decorator in that way?


Solution

  • I'm not sure about sitemesh v2. I've looked at their documentation and was unable to find anything relating to Java configuration. If you updated to v3 you could subclass ConfigurableSiteMeshFilter and override the applyCustomConfiguration method. More can be found at http://wiki.sitemesh.org/wiki/display/sitemesh3/Configuring+SiteMesh+3. Example from that link provided below

    public class MySiteMeshFilter extends ConfigurableSiteMeshFilter {
    
      @Override
      protected void applyCustomConfiguration(SiteMeshFilterBuilder builder) {
           // Map default decorator. This shall be applied to all paths if no other paths match.
           builder.addDecoratorPath("/*", "/default-decorator.html") 
           // Map decorators to path patterns. 
           .addDecoratorPath("/admin/*", "/another-decorator.html")
           .addDecoratorPath("/*.special.jsp", "/special-decorator.html")
           // Map multiple decorators to the a single path.
           .addDecoratorPaths("/articles/*", "/decorators/article.html",
                                             "/decoratos/two-page-layout.html", 
                                             "/decorators/common.html")
           // Exclude path from decoration.
           .addExcludedPath("/javadoc/*")
           .addExcludedPath("/brochures/*");
     }
    
    }