Announcement Announcement Module
Collapse
No announcement yet.
Set Tiles put-attribute from within Spring controller? Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • 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:
    Code:
    <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" />
    </definition>
    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.

    Code:
    <definition name="students.edit" extends="baseLayout">
        <put-attribute name="content" value="/WEB-INF/views/students/edit.jsp" />
    </definition>
    
    <definition name="students.list" extends="baseLayout">
        <put-attribute name="content" value="/WEB-INF/views/students/list.jsp" />
    </definition>
    
    <definition name="students.view" extends="baseLayout">
        <put-attribute name="content" value="/WEB-INF/views/students/view.jsp" />
    </definition>
    
    <definition name="course.edit" extends="baseLayout">
        <put-attribute name="content" value="/WEB-INF/views/courses/edit.jsp" />
    </definition>
    
    <definition name="courses.list" extends="baseLayout">
        <put-attribute name="content" value="/WEB-INF/views/courses/list.jsp" />
    </definition>
    
    <definition name="courses.view" extends="baseLayout">
        <put-attribute name="content" value="/WEB-INF/views/courses/view.jsp" />
    </definition>
    ...
    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
    Code:
        SomeAwesomeTilesClass.setAttribute("content", "/WEB-INF/views/courses/view.jsp");
        return "baseLayout";

  • #2
    The solution to your problem is using Tiles wildcards: http://forum.springsource.org/showth...with-wildcards
    Last edited by asambol; Feb 3rd, 2012, 08:25 AM.

    Comment

    Working...
    X