Hi all,
I was trying some of the new Tiles 2.1 features today, specifically
cascading attributes. I like this new feature a lot and it seems to
finally solve some of the challenges I have faced with tiles in the
past.
I am using the newest tiles release (2.1.0 beta) in conjunction with
Spring Web MVC.
However, I have run into what seems to be a rather strange problem.
First, let me show you my definitions:
<definition name="wrapper" template="/layouts/wrapper.jsp">
<put-attribute name="content" value="/common/blank.jsp"/>
</definition>
<definition name="leftColumnMain" extends="wrapper">
<put-attribute name="content" value="/layouts/leftColumnMain.jsp"/>
<put-attribute name="main" value="/common/blank.jsp"
cascade="true"/>
<put-attribute name="sidebar" value="/common/blank.jsp"
cascade="true"/>
</definition>
<definition name="leftColumnTest" template="/pages/leftColumnTest.jsp"/>
Essentially, I am constructing a "base" layout - the wrapper - which
contains just the most common items (wrapper.jsp) :
<%-- taglibs removed for brevity --%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd
">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<title>Left Column Main</title>
</head>
<body>
<tiles:insertAttribute name="content"/>
</body>
</html>
which is then extended by a more specific layout which defines a 67%
left column and 33% right column (leftColumnMain.jsp) :
<%-- taglibs removed for brevity --%>
<!-- Left column. -->
<div class="prepend-2 span-31 last">
<tiles:insertAttribute name="main"/>
</div>
<!-- Closes left column. -->
<!-- Right column. -->
<div class="prepend-1 span-14 append-1 last">
<tiles:insertAttribute name="sidebar"/>
</div>
<!-- Closes right column. -->
which is then used for a "leaf node" page just to test all this out
(leftColumnTest.jsp) :
<%-- taglibs removed for brevity --%>
<tiles:insertDefinition name="leftColumnMain">
<tiles:putAttribute name="main" cascade="true">
<p>This is left column content.</p>
</tiles:putAttribute>
<tiles:putAttribute name="sidebar" cascade="true">
<p>This goes in the sidebar.</p>
</tiles:putAttribute>
</tiles:insertDefinition>
I am now finding that when I render these definitions, I get "This is
the left column content." in place of both the "main" AND "sidebar"
attribute. Of course, I would expect to see the main content in the
main, left column and then the sidebar content in the other column -
but I only see the main content. Can anyone spot my mistake? Could
this be a bug, or am I just overlooking something simple?
It gets even weirder -- when I decide to change the order of the
tiles:putAttribute tags in my leftColumnTest.jsp, I can produce the
exact opposite results:
<tiles:insertDefinition name="designLeftColumnMain">
<tiles:putAttribute name="sidebar" cascade="true">
<p>This goes in the sidebar.</p>
</tiles:putAttribute>
<tiles:putAttribute name="main" cascade="true">
<p>This is left column content.</p>
</tiles:putAttribute>
</tiles:insertDefinition>
By putting the sidebar first, now "This goes in the sidebar" is
rendered twice in both places. So, this leads be to believe that
somehow something is being overwritten and that the "name" attribute
is not really being respected.
Perhaps also this is a bug with the new cascade behavior? If anyone
can provide me with help on how to recreate this sort of inheritance
without using the cascade attribute, I would be very gracious! I have
struggled for quite a few hours now trying to get this sort of
template structure working.
Thanks in advance for any help or insight you can give...
Best,
Zach Bailey
[EMAIL PROTECTED]