0

I'm looking for a way to dynamically load layouts based on some value set in some bean. Using Spring MVC with apache tiles.

Inside my views.xml I would typically have something like:

<definition extends="mytemplate" name="home">
    <put-attribute name="title" value="Home Page Title"/>
    <put-attribute name="heading" value="Home"/>
    <put-attribute name="body" value="/WEB-INF/pages/home.jspx"/> 
    <put-attribute name="side" value="/WEB-INF/pages/side.jspx"/> 
</definition>

and then inside mytemplate.jspx there would be code defining what the template looks like.

What I'm looking for is a way to change the mytemplate depending on some URL logic (check if incoming url is www.example1.com or www.example2.com), intercepting the url via RequestInterceptor, setting a value in a ThemeLayoutBean and then based on whether it is url1 or url2, have mytemplate1 and mytemplate2, each one having a completely different layout.

Jan Vladimir Mostert
  • 12,380
  • 15
  • 80
  • 137

1 Answers1

0

Apache Tiles has advanced view preparers which will allow me to do what I need to do in a slightly different way. http://tiles.apache.org/framework/tutorial/advanced/preparer.html

Jan Vladimir Mostert
  • 12,380
  • 15
  • 80
  • 137
  • Hi, do you have an example of how you were able to achieve the dynamic layout with view preparers? I am trying to do something similar. – aprajitha Mar 18 '15 at 03:05
  • Have a look at the Spring Roo Pizza Example, after you've scaffolded the models, type in web mvc setup and you'll get all the Apache tiles goodness and you can work from that example. I don't actually have the code anymore, but that was my starting point. Switched from JSP types of layouts to single page javascript / dart driven layouts where Spring's only purpose is responding to JSON requests from the javascript / dart. – Jan Vladimir Mostert Mar 18 '15 at 04:34