Hi, Please see my answers below:
On 12-08-22 08:30 PM, HC wrote: > Hi, > > I have a the following requirement and am trying to figure out how to make > this happen in spring mvc and tiles. > > 1. A user should be able to assemble a final page layout by picking or ore > more page elements from a library of page element templates. > 2. A user should be able to specify the order of page elements rendered on > the page. [...] > Tiles seems to have a "runtime composition" capability through the tiles > container API to do the above: > http://tiles.apache.org/2.2/framework/tutorial/advanced/runtime.html Absolutely! > Per the examples I have tried the following in my spring mvc controller. I > have also configured to use a mutable container in my TilesConfigurer. I think you don't need a mutable tiles container (that's for situations even more weird, basically when you use the tag <tiles:definition>, not <tiles:insertDefinition> with <tiles:putAttribute>). Let's keep it as simple as possible. I also think you shouldn't need nor attempt to use the Java API for Tiles inside the controller, that looks awkward and hard to maintain (if you really want to use the API, you should create your own View subclass in Spring MVC...). Here is what I would suggest on the spot (I didn't test it, but I think it should be much easier): @RequestMapping(...) public String index(Model model) { model.addAttribute("elements", Arrays.asList( "/WEB-INF/views/element_xyz.jspx", "/WEB-INF/views/element_abc.jspx")); return "universaltask/index"; } and then deal with it in a JSP. Something like: <tiles:insertDefinition name="elementContainer"> <tiles:putListAttribute name="elementList"> <c:forEach var="element" items="${elements}"> <tiles:addAttribute value="${element}" type="template"/> </c:forEach> </tiles:putListAttribute> </tiles:insertDefinition> or even: <c:forEach var="element" items="${elements}"> <tiles:insertTemplate template="${element}"/> </c:forEach> You may also try and convert the individual elements into Tiles definitions themselves, instead of template JSPs, and pass some contextual information through tiles: <c:forEach var="element" items="${elements}" varStatus="status"> <tiles:insertDefinition name="${element}"> <tiles:putAttribute name="environment" value="ShoppingBasket" /> <!-- or value="Order" if we display the element as part of an order instead of a shopping basket --> <tiles:putAttribute name="rownum" value="${status.count}" /> </tiles:insertDefinition> </c:forEach> Does that appear like what you're looking for? Nick.
