Announcement Announcement Module
No announcement yet.
Set Tiles put-attribute from within Spring controller? Page Title Module
Move Remove Collapse
Conversation Detail Module
  • Filter
  • Time
  • Show
Clear All
new posts

  • Set Tiles put-attribute from within Spring controller?

    Until now I've used JSP for my views. I'm converting over to Tiles, but I have a question before I move any further. I have my tiles set up and working, but I'm seeing a possible painful issue.

    Here's my example:
    <definition name="baseLayout" template="/WEB-INF/layouts/baseLayout.jsp">
        <put-attribute name="header" value="/WEB-INF/layouts/header.jsp" />
        <put-attribute name="menu" value="/WEB-INF/layouts/menu.jsp" />
        <put-attribute name="content" value="" />
        <put-attribute name="footer" value="/WEB-INF/layouts/footer.jsp" />
    The way I am understanding Tiles, I need to create separate definition for every page that needs to replace "content". Then in my Spring Controller method I return the definition name to display that page.

    <definition name="students.edit" extends="baseLayout">
        <put-attribute name="content" value="/WEB-INF/views/students/edit.jsp" />
    <definition name="students.list" extends="baseLayout">
        <put-attribute name="content" value="/WEB-INF/views/students/list.jsp" />
    <definition name="students.view" extends="baseLayout">
        <put-attribute name="content" value="/WEB-INF/views/students/view.jsp" />
    <definition name="course.edit" extends="baseLayout">
        <put-attribute name="content" value="/WEB-INF/views/courses/edit.jsp" />
    <definition name="courses.list" extends="baseLayout">
        <put-attribute name="content" value="/WEB-INF/views/courses/list.jsp" />
    <definition name="courses.view" extends="baseLayout">
        <put-attribute name="content" value="/WEB-INF/views/courses/view.jsp" />
    If I have 100's of pages, that's 100's of definitions. That definition file is going to get huge. Is there any way to set the put-attribute "content" from within a Spring Controller method?

    something like
        SomeAwesomeTilesClass.setAttribute("content", "/WEB-INF/views/courses/view.jsp");
        return "baseLayout";

  • #2
    The solution to your problem is using Tiles wildcards:
    Last edited by asambol; Feb 3rd, 2012, 07:25 AM.