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.
So, I am thinking of having various jsp pages as the page elements and a master template with a body tiles attribute which will render all the elements the user chooses to have rendered. I saw tiles has the List Attribute capability through which I would be able to populate the body attribute multiple jsps.
http://tiles.apache.org/2.2/framewor...ttributes.html
However, since the user has control over what goes in the page, the tiles definition happens at runtime by the user. That means I need a runtime way of expressing what jsps goes into the body tag and in what order.
Tiles seems to have a "runtime composition" capability through the tiles container API to do the above:
http://tiles.apache.org/2.2/framewor...d/runtime.html
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.
The above fails with the following error or other very similar messages depending on the renderer:Code:@RequestMapping(method = RequestMethod.GET, value = "/") public ModelAndView index(ModelAndView mv, HttpServletRequest request, HttpServletResponse response) throws Exception { MutableTilesContainer container = (MutableTilesContainer) ServletUtil.getCurrentContainer(request, request.getSession().getServletContext()); ListAttribute tiles = new ListAttribute(); Attribute attr = new Attribute("/WEB-INF/views/element_xyz.jspx"); tiles.add(attr); attr = new Attribute("/WEB-INF/views/element_abc.jspx"); tiles.add(attr); AttributeContext context = container.startContext(request, response); context.putAttribute("body", tiles); //don't call container.render(...) since spring mvc does that for me //don't call container.stopContext(...) since spring mvc does that for me mv.setViewName("universaltask/index"); mv.getModelMap().put("app_name", "My App"); return mv; }
org.apache.tiles.impl.InvalidTemplateException: Cannot render a template that is not a string: [/WEB-INF/views/element_xyz.jspx]
at org.apache.tiles.renderer.impl.TemplateAttributeRe nderer.write(TemplateAttributeRenderer.java:46)
at org.apache.tiles.renderer.impl.AbstractBaseAttribu teRenderer.render(AbstractBaseAttributeRenderer.ja va:106)
at org.apache.tiles.impl.BasicTilesContainer.render(B asicTilesContainer.java:670)
at org.apache.tiles.impl.BasicTilesContainer.render(B asicTilesContainer.java:336)
at org.apache.tiles.template.InsertAttributeModel.ren derAttribute(InsertAttributeModel.java:210)
at org.apache.tiles.template.InsertAttributeModel.end (InsertAttributeModel.java:126)
at org.apache.tiles.jsp.taglib.InsertAttributeTag.doT ag(InsertAttributeTag.java:311)
at org.apache.jsp.WEB_002dINF.layouts.default_jspx._j spx_meth_tiles_insertAttribute_1(org.apache.jsp.WE B_002dINF.layouts.default_jspx:144)
at org.apache.jsp.WEB_002dINF.layouts.default_jspx._j spService(org.apache.jsp.WEB_002dINF.layouts.defau lt_jspx:70)
at org.apache.jasper.runtime.HttpJspBase.service(Http JspBase.java:109)
at javax.servlet.http.HttpServlet.service(HttpServlet .java:820)
at org.apache.jasper.servlet.JspServletWrapper.servic e(JspServletWrapper.java:389)
at org.apache.jasper.servlet.JspServlet.serviceJspFil e(JspServlet.java:486)
at org.apache.jasper.servlet.JspServlet.service(JspSe rvlet.java:380)
at javax.servlet.http.HttpServlet.service(HttpServlet .java:820)
at org.eclipse.jetty.servlet.ServletHolder.handle(Ser vletHolder.java:538)
at org.eclipse.jetty.servlet.ServletHandler.doHandle( ServletHandler.java:478)
at org.eclipse.jetty.server.handler.ScopedHandler.han dle(ScopedHandler.java:119)
at org.eclipse.jetty.security.SecurityHandler.handle( SecurityHandler.java:517)
at org.eclipse.jetty.server.session.SessionHandler.do Handle(SessionHandler.java:225)
at org.eclipse.jetty.server.handler.ContextHandler.do Handle(ContextHandler.java:937)
at org.eclipse.jetty.servlet.ServletHandler.doScope(S ervletHandler.java:406)
at org.eclipse.jetty.server.session.SessionHandler.do Scope(SessionHandler.java:183)
at org.eclipse.jetty.server.handler.ContextHandler.do Scope(ContextHandler.java:871)
at org.eclipse.jetty.server.handler.ScopedHandler.han dle(ScopedHandler.java:117)
at org.eclipse.jetty.server.Dispatcher.forward(Dispat cher.java:284)
at org.eclipse.jetty.server.Dispatcher.forward(Dispat cher.java:115)


Reply With Quote
