tags:

views:

92

answers:

1

I have a tiles-defs.xml that has these definitions...

<definition name="masterLayout" path="/WEB-INF/tiles-layouts/globalLayout.jsp">
    <put name="pageTemplate" value="over-ride for each page" />
</definition>

<definition name="childLayout" extends="masterLayout">
    <put name="pageTemplate" value="/WEB-INF/tiles-layouts/child/layout.jsp" />
    <put name="title" value="page title" />
    <put name="metaKeywords"    value="" />
    <put name="metaDescription" value="" />
    <put name="body"            value="/child/pagebody.jsp"/>
    <putList name="list">
        <add value="title" />
        <add value="metaKeywords" />
        <add value="metaDescription" />
        <add value="body" />
    </putList>
</definition>

in globalLayout.jsp I have this working, but I won't always know what attributes the child definition has added to the page.

<tiles:insert attribute="pageTemplate">
<tiles:put name="title"><tiles:getAsString name="title" /></tiles:put>
<tiles:put name="metaKeywords"><tiles:getAsString name="metaKeywords" /></tiles:put>
<tiles:put name="metaDescription"><tiles:getAsString name="metaDescription" /></tiles:put>
<tiles:put name="body"><tiles:getAsString name="body" /></tiles:put>

Since the child definition won't always include the same attributes. Is there a way to use the putList in the child definition to put the attributes into the child page's scope inside of globalLayout.jsp? I've tried the following, but it fails

<%@ page import="java.util.Iterator" %>
<tiles:importAttribute />
<bean:define id="list" name="list" type="java.util.List" scope="page" />
<tiles:insert attribute="pageTemplate" ignore="true" flush="true">
    <%
    for ( Iterator it = list.iterator(); it.hasNext(); ) {
        String item = (String) it.next();
    %>
        <tiles:put name="<%=item%>"><tiles:getAsString name="<%=item%>" ignore="true" /></tiles:put>
    <% } %>
</tiles:insert>
A: 

instead of trying to push the attributes down to a child layout, I pulled the child layout up into the scope of the parent layout.

<tiles:importAttribute name="pageTemplate" />
<bean:define id="pageTemplate" name="pageTemplate" />
<jsp:include flush="true" page="<%=pageTemplate%>"></jsp:include>
David