Question

I am new to tiles and simply wish to make them work in the following scope base.jsp

...<body id="pageBody">
<div id="container">
      <tiles:insertAttribute name="intro"/>
      <tiles:insertAttribute name="supportingText"/>
      <tiles:insertAttribute name="menu"/>
</div>

...

where intro.jsp is

    <div id="intro">
  <tiles:insertAttribute name="header" />
  <tiles:insertAttribute name="quickSummary" />
  <tiles:insertAttribute name="preamble" />
</div>

So in simple terms, I wish to have a tile definition named intro which is to be used inside a tile definition named base.jsp

in my tiles-defs.xml I have:

<tiles-definitions>

<definition name="base" template="/WEB-INF/tiles/base.jsp">
    <put-attribute name="title" value="Template"/>
    <put-attribute name="content" value="/WEB-INF/tiles/header.jsp"/>
    <put-attribute name="footer" value="/WEB-INF/tiles/footer.jsp"/>
    <put-attribute name="intro" value="intro"/>
    <put-attribute name="menu" value="/WEB-INF/tiles/menu.jsp"/>
    <put-attribute name="resources" value="/WEB-INF/tiles/resources.jsp"/>
    <put-attribute name="supportingText" value="/WEB-INF/tiles/supportingText.jsp"/>
</definition>

<definition name="intro" template="/WEB-INF/tiles/intro.jsp">
    <put-attribute name="header" value="/WEB-INF/tiles/header.jsp"/>
    <put-attribute name="quickSummary" value="/WEB-INF/tiles/quickSummary.jsp"/>
    <put-attribute name="preamble" value="/WEB-INF/tiles/preamble.jsp"/>
</definition>

So I was hopping this would work and the content of header.jsp, quickSummary.jsp, preamble.jsp would be available in the rendered page.

Instead I get as final result:

...</head> <body id="pageBody"> <div id="container"> <div id="intro"> <tiles:insertAttribute name="header" /> <tiles:insertAttribute name="quickSummary" /> <tiles:insertAttribute name="preamble" /> </div> <div id="supportingText"> <tiles:insertAttribute name="content"/> <tiles:insertAttribute name="footer"/> </div> <div id="linkList"> <div id="linkList2">...

In my spring configuration I have:

    <bean id="tilesConfigurer" class="org.springframework.web.servlet.view.tiles2.TilesConfigurer" p:definitions="/WEB-INF/tiles-defs/tiles-defs.xml" />
<bean id="tilesViewResolver" class="org.springframework.web.servlet.view.ResourceBundleViewResolver" p:basename="views" />

Any ideas if what I am trying to do is feasible (sounds really common scenario so I guess it is) and if yes what I do wrong?

Was it helpful?

Solution

Add cascade="true" to put-attributes to cascade header, quickSummary and preamble to nested tiles.

See also documentation about nesting definitions.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top