tiles-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From HC <canterbu...@gmail.com>
Subject How can I do "runtime composition" with tiles and spring mvc?
Date Thu, 23 Aug 2012 00:30:54 GMT
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/framework/tutorial/advanced/list-attributes.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/framework/tutorial/advanced/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.

@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);
 mv.setViewName("universaltask/index");
mv.getModelMap().put("app_name", "My App");
return mv;
}


The above fails with the following error or other very similar messages
depending on the renderer:

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.TemplateAttributeRenderer.write(TemplateAttributeRenderer.java:46)
at
org.apache.tiles.renderer.impl.AbstractBaseAttributeRenderer.render(AbstractBaseAttributeRenderer.java:106)
at
org.apache.tiles.impl.BasicTilesContainer.render(BasicTilesContainer.java:670)
at
org.apache.tiles.impl.BasicTilesContainer.render(BasicTilesContainer.java:336)
at
org.apache.tiles.template.InsertAttributeModel.renderAttribute(InsertAttributeModel.java:210)
at
org.apache.tiles.template.InsertAttributeModel.end(InsertAttributeModel.java:126)
at
org.apache.tiles.jsp.taglib.InsertAttributeTag.doTag(InsertAttributeTag.java:311)
at
org.apache.jsp.WEB_002dINF.layouts.default_jspx._jspx_meth_tiles_insertAttribute_1(org.apache.jsp.WEB_002dINF.layouts.default_jspx:144)
at
org.apache.jsp.WEB_002dINF.layouts.default_jspx._jspService(org.apache.jsp.WEB_002dINF.layouts.default_jspx:70)
at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:109)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:820)
at
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:389)
at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:486)
at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:380)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:820)
at org.eclipse.jetty.servlet.ServletHolder.handle(ServletHolder.java:538)
at
org.eclipse.jetty.servlet.ServletHandler.doHandle(ServletHandler.java:478)
at
org.eclipse.jetty.server.handler.ScopedHandler.handle(ScopedHandler.java:119)
at
org.eclipse.jetty.security.SecurityHandler.handle(SecurityHandler.java:517)
at
org.eclipse.jetty.server.session.SessionHandler.doHandle(SessionHandler.java:225)
at
org.eclipse.jetty.server.handler.ContextHandler.doHandle(ContextHandler.java:937)
at org.eclipse.jetty.servlet.ServletHandler.doScope(ServletHandler.java:406)
at
org.eclipse.jetty.server.session.SessionHandler.doScope(SessionHandler.java:183)
at
org.eclipse.jetty.server.handler.ContextHandler.doScope(ContextHandler.java:871)
at
org.eclipse.jetty.server.handler.ScopedHandler.handle(ScopedHandler.java:117)
at org.eclipse.jetty.server.Dispatcher.forward(Dispatcher.java:284)
at org.eclipse.jetty.server.Dispatcher.forward(Dispatcher.java:115)

Mime
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message