Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>If every page in your system needs to display a kind of pane, then you can provide the model data for this using an <a href="http://static.springsource.org/spring/docs/1.2.x/reference/mvc.html#mvc-handlermapping-interceptor" rel="nofollow noreferrer">interceptor</a>. This is almost always preferable to putting code in an abstract controller (as suggested in another answer) because that then forces you to always extend that from that particular class hierarchy.</p> <pre><code>public class YourInterceptor extends HandlerInterceptorAdapter { private Repository repository; public void setRepository (Repository repository) { this.repository = repository; } public boolean preHandle( HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception { List&lt;Post&gt; posts = repository.getNewPosts(); List&lt;Items&gt; items= repository.getItems(); request.setAttribute("model", new MyCommonViewModel(posts,items)); } } </code></pre> <p>wiring it up like</p> <pre><code>&lt;beans&gt; &lt;bean id="handlerMapping" class="org.springframework.web.servlet.handler.SimpleUrlHandlerMapping"&gt; &lt;property name="interceptors"&gt; &lt;list&gt; &lt;ref bean="yourInterceptor"/&gt; &lt;/list&gt; &lt;/property&gt; &lt;property name="mappings"&gt; &lt;props&gt; &lt;!-- SNIP --&gt; &lt;/props&gt; &lt;/property&gt; &lt;/bean&gt; &lt;bean id="yourInterceptor" class="your.YourInterceptor"&gt; &lt;property name="repository"&gt;&lt;ref bean="repository" /&gt;&lt;/property&gt; &lt;/bean&gt; &lt;beans&gt; </code></pre> <p>You could also look at using something like <a href="http://www.opensymphony.com/sitemesh/" rel="nofollow noreferrer">sitemesh</a>. This allows you to create a template page which is a base for all your other pages (or certain sets of pages depending on how you configure it). This would prevent you from having to include the pane jsp on every page. But if your project is small enough it may not be worth the bother.</p>
 

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