Note that there are some explanatory texts on larger screens.

plurals
  1. PODynamic includes in JSP template
    text
    copied!<p>I've just started studying Spring, and I'm trying to make a web application. I have some common UI elements such as footer, header, sidebar and also want to add dynamic blocks, i.e. widgets. What widgets to include need to be chosen in Java code, not JSP template.</p> <p>And that's where I'm stuck. Every controller returns it's own view - <code>main.jsp</code> which includes some static and dynamic blocks:</p> <pre><code> &lt;jsp:include page="head.jsp" /&gt; &lt;c:forEach items="${viewList}" var="viewName"&gt; &lt;jsp:include page="${viewName}.jsp" /&gt; &lt;/c:forEach&gt; ... </code></pre> <p>In controler I'm passing view list and object that will be used as widget to model:</p> <pre><code> ... views.add(moduleOne.getViewName()); views.add(moduleTwo.getViewName()); model.addAllAttributes(moduleOne.getAttr()); model.addAllAttributes(moduleTwo.getAttr()); model.addAttribute(IModule.VIEW_LIST, views); // passing all views that will be included into main.jsp ... return "main"; </code></pre> <p>But it doesn't work because when I use <code>jsp:include page</code> model parameters do not pass to includee. Also I can't <code>%@include file=</code> because in that case I won't be able to use variables and I would need to know which view to pass at compile time.</p> <p>Of course if there's no solution, I'll have to hardcode all possible widget views in <code>main.jsp</code> and switch between them:</p> <pre><code> switch($i) { case 1: include file=widget1.jsp; break; case 2: include file=widget2.jsp; break; ... } </code></pre> <p>Which is obviously not flexible.</p> <p>So, the questions are:</p> <ol> <li>Is there any way to solve the problem of passing model to include views without using <code>%@include file=</code> and make my widgets working? </li> <li>Is there some better way to implement such widgets structure?</li> </ol> <p>Thank you! </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