Note that there are some explanatory texts on larger screens.

plurals
  1. POSpring Tiles: Add context information (menu, title)
    primarykey
    data
    text
    <p>I am wondering what is the best way to add context information (like the current menu or the title of the page) to spring 3 + tiles 2 app.</p> <p>I want the system to be as easily extenable as possible, so for example my tiles config uses a wildcards, because I do not want to write a new entry for every new request handler:</p> <pre><code>&lt;tiles-definitions&gt; &lt;definition name="baseLayout" template="/WEB-INF/jsp/layout.jsp"&gt; &lt;put-attribute name="title" value="Template" /&gt; &lt;put-attribute name="header" value="/WEB-INF/jsp/header.jsp" /&gt; &lt;put-attribute name="menu" value="/WEB-INF/jsp/menu.jsp" /&gt; &lt;put-attribute name="body" value="/WEB-INF/jsp/content.jsp" /&gt; &lt;put-attribute name="footer" value="/WEB-INF/jsp/footer.jsp" /&gt; &lt;/definition&gt; &lt;definition name="**-tile" extends="baseLayout"&gt; &lt;put-attribute name="title" value="{1}" /&gt; &lt;put-attribute name="body" value="/WEB-INF/jsp/{1}.jsp" /&gt; &lt;/definition&gt; &lt;/tiles-definitions&gt; </code></pre> <p>So I guess the only choice left is to add stuff to the model. I could of course add a new model entry (e.g. MODEL_ID) for every requesthandler, like this:</p> <pre><code>@RequestMapping(value="/order/{orderId}.x") public String showOrder(ModelMap model, @PathVariable long orderId) { // do stuff model.addAttribute(Context.MODEL_ID, Context.getOrderContext()); } </code></pre> <p>and then this particular MODEL_ID is interpreted in title.jsp to show a title and in menu.jsp to highlight the current menu item.</p> <p>However, I do not like the idea of adding those lines to all request methods of all my controllers. </p> <p>I was thinking about writing an Interceptor which tries to determine the "context" based on the name of the view or requestpath, but then I have to rewrite all URLs in the interceptor and also keep them in sync with the Controllers.</p> <p>What is the correct or simpliest way to add context info to every controller to use in common tiles?</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload