It is an expected behavior ! Tiles can be seen like functions : they takes
parameters, and parameters are only visible inside the function, not outside,
neither in called functions.

  This behavior allows to write a Tile without taking care about possible
conflicts with attribute names.
  Imagine that you write a complex page with several nested Tiles, and several
time the same Tile with different values for the same attribute. If you "cascade"
attributes, you will have names clashing. Furthermore, while developing a Tile
you will need to thing about the names used in the whole page and in other Tiles,
to avoid possible conflict ! This will forbid reusable Tiles.

  If you want to use an attribute value inside another inserted Tile, you have to
pass it explicitly. In your example, you could write something like :
layout.jsp
-- CUT --
<tiles:insert path="/header.jsp">
  <put beanName="title" beanScope="template" />
         // In future release, beanScope will accept "tiles" also (same as
template)
</tiles:insert>
<tiles:insert attribute="content"/>
<tiles:insert path="/footer.jsp"/>
-- CUT --

Reading your example, I think you should better not cut a tag into two separate
files (<body> and </body>). Putting a start and end tag in the same file improve
legibility, and minimize potential errors (forget the closing tags, forget to
insert the corresponding file, ...).

  Cedric

Jim Crossley wrote:

> Apparently it's not possible to access attributes of any tiles other
> than your immediate "parent".  IMHO, this restricts my ability to
> partition my presentation code into simple, reusable chunks.
>
> Here's a semi-practical example.
>
> Consider this snippet from a definitions file...
>
>   <definition name="training" path="/layout.jsp">
>     <put name="content" value="/training.jsp"/>
>     <put name="title"   value="Training"/>
>   </definition>
>
> layout.jsp
> -- CUT --
> <tiles:insert path="/header.jsp"/>
> <tiles:insert attribute="content"/>
> <tiles:insert path="/footer.jsp"/>
> -- CUT --
>
> header.jsp
> -- CUT --
> <html>
>   <head>
>     <title><tiles:getAsString name="title"/></title>
>   </head>
>   <body>
> -- CUT --
>
> footer.jsp
> -- CUT --
>   </body>
> </html>
> -- CUT --
>
> The above example, as simple as it is, won't work, because header.jsp
> can't find the attribute named "title".
>
> Have I completely misunderstood the intent behind Tiles, or is it
> simply not quite ready for prime time?  Is there a better (simpler)
> approach than the one taken in the above example?
>
> -- Jim
>
> --
> To unsubscribe, e-mail:   <mailto:[EMAIL PROTECTED]>
> For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>


--
To unsubscribe, e-mail:   <mailto:[EMAIL PROTECTED]>
For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>

Reply via email to