views:

636

answers:

1

I'm working on a project using Apache Tiles 2.1.

I am running into an issue where extending templates with list attributes is creating duplicates of those list items... one set of duplicates for each level of inheritance.

As an example, here is the base definition, and the page it would produce:

<definition name="base" template="somePage.jsp">
    <!-- snip -->
    <put-list-attribute name="styles">
        <add-attribute value="base.css"/>
    </put-list-attribute>
</definition>

This would produce html like this, as expected:

<html>
    <head>
        <!-- snip -->
        <link rel="stylesheet" type="text/css" href="../css/base.css"/>
    </head>
    <body>
         <!-- snip-->
    </body>
</html>

If I extend the definiton like this:

<definition name="firstExtension" extends="base">
    <!-- snip -->
    <put-list-attribute name="styles" inherit="true">
        <add-attribute value="someOther.css"/>
    </put-list-attribute>
</definition>

Again, as expected, I get this result:

<html>
    <head>
        <!-- snip -->
        <link rel="stylesheet" type="text/css" href="../css/base.css"/>
        <link rel="stylesheet" type="text/css" href="../css/someOther.css"/>
    </head>
    <body>
         <!-- snip-->
    </body>
</html>

However, if I extend the previous one, the problems start:

<definition name="secondExtension" extends="firstExtension">
    <!-- snip -->
    <put-list-attribute name="styles" inherit="true">
        <add-attribute value="evenMore.css"/>
    </put-list-attribute>
</definition>

This second level extension produces this:

<html>
    <head>
        <!-- snip -->
        <link rel="stylesheet" type="text/css" href="../css/base.css"/>
        <link rel="stylesheet" type="text/css" href="../css/base.css"/> <!-- note: duplicate! -->
        <link rel="stylesheet" type="text/css" href="../css/someOther.css"/>
        <link rel="stylesheet" type="text/css" href="../css/evenMore.css"/>
    </head>
    <body>
         <!-- snip-->
    </body>
</html>

The "original" lists attributes that are inherited get duplicated once for each extended definition, even if that definition does not add anything to the list attribute.

I'm trying to keep my definitions very DRY, so I have 4-5 levels of inheritance in some cases. So the "always used" css files get duplicated 4-5 times, even when only the "lowest" definition is the only one to add another css file to the list.

Is this a bug in tiles, or am I simply using them in a way that was not intended? Is there some way I could remedy this problem without simply eliminating the inherit="true" ? I'd like to avoid writing the same "core" css and javascript files on every single definition if possible.

+1  A: 

Turns out that this is indeed a bug in Apache tiles 2.1.2, not a configuration problem on my end.

It has been fixed and will be included in the 2.1.3 update:

See the tiles JIRA issue about it.

TM