How to include tile definition attributes on an inserted page

I have patch-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 This works for me, but I won’t always know what attributes the child definition on the page defined.

<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 definition of child does not always include the same attributes. Is there a way to use putList in a child definition to place attributes in the area of ​​the child page inside globalLayout.jsp? I 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>
+3
source share
2 answers

instead of pushing attributes to the child layout, I pulled the child layout into the parent layout area.

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

Tiles 2 cascade="true" put-attributes . .

+12

Source: https://habr.com/ru/post/1761148/


All Articles