Use
a Tile Layout
In the previous section we created a layout
is common for both dog.jsp and cat.jsp , In
this section we will see how we can use that
layout for both dog.jsp and cat.jsp.
First
sep is to Import the tiles taglib with the taglib
directive.
<%@ taglib uri="/WEB-INF/struts-tiles.tld"
prefix="tiles" %>
Second
step is to Use tiles:insert to insert the tile
layout into the current page.
<tiles:insert
page="/layout.jsp" flush="true">
<tiles:put name="title" type="string"
value="DOG" />
<tiles:put name="header" value="/header.jsp"
/>
<tiles:put name="footer" value="/footer.jsp"
/>
<tiles:put name="content" value="/dogContent.jsp"/>
</tiles:insert>
Third
step is to Use tiles:put to pass string parameters.
<tiles:put
name="title" type="string"
value="Dog" />
Notice
how tiles:put passes string parameters to the
tile layout. The tiles:put's name attribute
tag specifies the parameter name. The tiles:put's
type attribute specifies the parameter's type.
Lastly, the value parameter is passed the title
attribute's value. That lets you pass simple
strings as parameters when the tile layout (display
function) gets called with the tiles:insert
tag. The parameters become tile
layout attributes; that is, they get inserted
into the tile scope of the tile layout.
Fourth
step is to Use tiles:put to pass in parameter
tiles.
<tiles:put
name="header" value="/header.jsp"
/>
<tiles:put name="footer" value="/footer.jsp"
/>
<tiles:put name="content" value="/dogContent.jsp"/>
|