Search code examples
javajspsitemesh

Advanced templating with jsp and sitemesh


Here's what i am trying to do:

I have a main template with header, menubar, body and footer. The body is replaced by the actual page called with the help of sitemesh like this:

<div class="main">
  <decorator:body />
</div>

Same for the title etc.

My problem is with the menubar: i would like to declare the content of the menubar in the actual page. The menus changes in every page, but i don't want to duplicate the layout of the menubar in every page.

My tools are JSP, Sitemesh and Spring MVC 3.

Is it possible? And if it is, how?


Solution

  • Here's how i did it :

    template.jsp :

    <div class="menubar" >
       <decorator:getProperty property="page.navig"></decorator:getProperty>
    </div>
    

    actualpage.jsp :

    <body>
       <content tag="navig">
          my menu \o/
       </content>
    ...
    </body>
    

    Note : without the 'page.' it does not work.