You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@struts.apache.org by de...@struts.apache.org on 2004/12/02 06:41:18 UTC
[Apache Struts Wiki] New: StrutsDocTiles
Date: 2004-12-01T21:41:18
Editor: BillKeese <bi...@tech.beacon-it.co.jp>
Wiki: Apache Struts Wiki
Page: StrutsDocTiles
URL: http://wiki.apache.org/struts/StrutsDocTiles
no comment
New Page:
##language:en
== Tips on Tiles ==
Here are some tips on using tiles.
=== Nested tiles ===
==== Problem ====
How do you do nested tiles? For example, suppose my .mainLayout is header/body/footer tiles.
||<#FF8080>Header||
||<#80FF80>Body||
||<#8080FF>Footer||
[[BR]]
However, for the edit page, I want to compose "body" from multiple subtiles.
||<#FF8080 -2> Header||
||<#80FF80>A||<#80FF80>B||
||<-2 #8080FF>Footer||
layout.jsp:
{{{
<tiles:insert attribute="header" />
<tiles:insert attribute="body"/ >
<tiles:insert attribute="footer" />
}}}
editBody.jsp:
{{{
<table>
<tr>
<td><tiles:insert attribute="a"/></td>
<td><tiles:insert attribute="b"/></td>
</tr>
</table>
}}}
So, had do I set the values of "a" and "b" from tiles-def.xml?
There are two possible ways.
==== Solution #1 ====
The first way is to use 2 definitions (plus the defaultLayout definition) in tiles-def.xml:
{{{
<definition name="defaultLayout" template="/WEB-INF/layout.jsp">
<put name="header" value="/WEB-INF/header.jsp" />
<!-- definitions based on this layout must define "body" -->
<put name="footer" value="/WEB-INF/footer.jsp" />
</definition>
<!-- first define the inner tile -->
<definition name="editpage.body" template="/WEB-INF/editBody.jsp">
<put name="a" value="/WEB-INF/a.jsp" />
<put name="b" value="/WEB-INF/b.jsp" />
</definition>
<!-- then define the whole page by referencing the inner tile -->
<definition name="editpage" extends="defaultLayout">
<put name="body" value="editpage.body" type="definition"/>
</definition>
}}}
This is a versatile solution but on the downside the tiles-def.xml file gets big.
==== Solution #2 ====
Another approach is to only use one definition (plus the defaultLayout definition) in the tiles-def.xml file.
tiles-def.xml:
{{{
<definition name="defaultLayout" template="/WEB-INF/layout.jsp">
<put name="header" value="/WEB-INF/header.jsp" />
<!-- definitions based on this layout must define "body" -->
<put name="footer" value="/WEB-INF/footer.jsp" />
</definition>
<definition name="editPage" extends="defaultLayout">
<put name="body" value="/WEB-INF/editBody.jsp" />
<put name="a" value="/WEB-INF/a.jsp" />
<put name="b" value="/WEB-INF/b.jsp" />
</definition>
}}}
layout.jsp:
{{{
<tiles:insert attribute="header">
<tiles:insert attribute="body" >
<!-- propogate "a" and "b" down to the next level -->
<tiles:put name="a" beanName="a"/>
<tiles:put name="b" beanName="b"/>
</tiles:insert>
<tiles:insert attribute="footer">
}}}
editBody.jsp:
{{{
<table>
<tr>
<td><tiles:insert attribute="a"/></td>
<td><tiles:insert attribute="b"/></td>
</tr>
</table>
}}}
The downside of this approach is that layout.jsp must know the list of possible arguments
to (any) body.jsp page.
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@struts.apache.org
For additional commands, e-mail: dev-help@struts.apache.org