Hi guys:
I'm trying to build a complex variation of interfaces using several
level of tiles extending. However, I'm having problem with declaring and
using tile attribute.

Here is a compact version of what I want to build:

Given I have these definition:
<definition name="master" template="/WEB-INF/layouts/master/master.jsp">
</definition>
<definition name="master-no-small" extends="master">
  <put-attribute name="content"
value="/WEB-INF/layouts/master/content-no-small.jsp"/>
</definition>

<definition name="master-small-left" extends="master">
<put-attribute name="content"
value="/WEB-INF/layouts/master/content-small-left.jsp"/>
</definition>

Inside content-no-small.jsp, I will use tiles:insertAttribute to include
an attribute named "body" that will be defined in later extension of
master-no-small

And inside content-small-left, I will use tiles:insertAttribute to
include an attribute named "side" that will be defined in later
extension of master-small-left.

The main idea is to have several sub-masters page that inherit from
theimportAttribute same master so that I can have several version of
interface that share some similar elements.

        <definition name="admin.moderators" extends="master-no-small">
                <put-attribute name="body"
                value="/WEB-INF/layouts/admin/admin-moderators.ftl" />
        </definition>

        <definition name="admin.site-settings" extends="admin.master">
                <put-attribute name="side"
value="/WEB-INF/layouts/admin/admin-site-settings.ftl" />
        </definition>

However, since the attribute won't be "passed through", I must use
importAttribute from the master template to pass "body" and "side"
attribute to the content, so the master.jsp would look like:

<tiles:importAttribute/>
<tiles:insertAttribute name="content">
  <tiles:putAttribute name="body" value="${body}">
  <tiles.putAttribute name="side" value="${side}">
</tiles:insertAttribute>

and init default value for both "body" and "side" attribute inside
definition of "master". So, it now would be like this:
<definition name="master"
                template="/WEB-INF/layouts/master/so/skeleton-so.jsp">
                <!-- Pre-init all possible attribute of the page -->
                <put-attribute name="side" value=""/>
                <put-attribute name="body" value=""/>
        </definition>


The problem is, I have to pass both "body" and "side" attribute to
"content-no-small.jsp" as well as "content-small-left.jsp" mean while
each of these two template needs only one attribute (either "body" or
"side").

This would be a small problem, but imagine I want to scale up to several
dozen variation of the interface (by add child, grand-child extensions),
each with their own attributes. And then declaration all of these
attributes (both in importAttribute and in definition of "master") would
be unreasonable. I hope there would be a better way to do that. Would
any body help me on that? I'm having googling for several whole days
with these phrases but didn't get it: "tiles passing attribute", "tiles
hierarchical definition". It would be excellent if anyone lighting me by
pointing out how tiles (specifically, tiles 2.1.2) passing attributes
around.

Thanks.
Phuong.

Reply via email to