You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by Lorrin Nelson <lh...@the-fam.net> on 2003/05/16 23:01:22 UTC
passing attributes to nested tiles
Hi - I'm confused about the proper way to get attributes from a tiles
definition to nested tiles. My definition looks like this:
<definition name="tiles.mainLayout" path="/private/common/MainLayout.jsp">
<put name="menu" value="/private/common/menu.jsp"/>
<put name="body" value="/private/common/blank.jsp" />
</definition>
<definition name="tiles.login" extends="tiles.mainLayout">
<put name="body" value="/private/login/login.jsp" />
<put name="headingMessage" value="welcome.heading"/>
</definition>
Inside MainLayout.jsp there is a <tiles:insert attribute='body' /> statement.
How do I make it so I can effectively do <bean:message
key="welcome.heading"/> inside login.jsp but with the key being specified
by the tiles "headingMessage" definition instead of hard-coded?
Thanks!
-Lorrin
---------------------------------------------------------------------
To unsubscribe, e-mail: struts-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: struts-user-help@jakarta.apache.org
Re: passing attributes to nested tiles
Posted by Jason Lea <ja...@kumachan.net.nz>.
Lorrin Nelson wrote:
> Hi Nick, thanks for advice! I was hoping it would be possible to do this
> without modifying MainLayout.jsp. For some tile definitions there will
> be no "headerMessage" needed by the body tile, or there will be a
> different parameter, or multiple paramters. Is there any way I can either
> a) just make everything from the definition available to the sub
> tile (I guess not...)
> or
> b) somehow use the tiles-defs.xml to not put in a raw String but
> a HashMap of Strings so that MainLayout.jsp can just make that HashMap
> available to the subtiles and I can change what's in there on definition
> by definition basis?
You might be able to use the <tiles:putList> and <tiles:add> tags or xml
definitions <putList> and <add> for an answer to (b).
--
Jason Lea
---------------------------------------------------------------------
To unsubscribe, e-mail: struts-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: struts-user-help@jakarta.apache.org
RE: passing attributes to nested tiles
Posted by Nick <nm...@adelphia.net>.
There is another way, but I think that it can make a mess of your
tiles-defs file if you're not careful. But first, as far as I have
seen, it doesn't cause a problem when a tile receives an attribute that
it doesn't use. It isn't as neat, but I've haven't seen any negatives
from doing it that way.
The alternative that I mention is to build up your pages in the tiles
xml, constructing working pages that have gaps that can be filled in by
another definition. I can show it better than I explain it...
As an example, my current project is developing a series of editors with
common features. I am working on a series of editor pages of...lets
just types that are all related and share many common attributes. I use
different tiles to construct the editor body, depending on the editor
need and the item being edited.
In my base definition, I create place holders for the low level
attributes:
<put name="functionButtons" value="{$defineForTopEditPages}" />
<put name="filterButtons" value="{$defineForTopEditPages}" />
<put name="buttons" value="{$defineForEditorDetailPages}" />
The place holders are brought into the layout jsp and then put into the
body as described in my earlier message. It doesn't cause a problem if
you use the above definition without setting a "usable" value: it will
just get discarded. I then use those attributes in later definitions,
for example:
<definition name=".internal.editWidgets" extends=".editorBasePage">
<put name="title" value="widgetEditor.title" />
<put name="headerText" value="widgetEditorEdit.header" />
<put name="body" value="/jsp/widgetDetail.jsp"/>
<put name="buttons" value="/tiles/editorEditButtons.jsp" />
</definition>
Note: ".internal.editWidgets" is what I call a working page. I wouldn't
forward to it, but it gives me just about everything that I need.
<definition name=".editor.editWidgetTypeA"
extends=".internal.editWidgets">
<put name="uniqueEditorBody" value="/jsp/widgetDetailTypeA.jsp" />
</definition>
<definition name=".editor.editWidgetTypeB"
extends=".internal.editWidgets">
<put name="uniqueEditorBody" value="/jsp/widgetDetailTypeB.jsp" />
</definition>
In my case, the buttons are passed through the layout into the
"widgetDetail" body. Similarly, the headerText is also passed through
the layout into the jsp that we use for the header.
The last two definitions use the working page to create the page that I
want the user to see. Both definitions fill in the gaps that were left
empty by the working definition.
I tend to use the "pass through" method for attributes that I think will
vary for all or most of my nested tiles. I use the "working page"
method for things that are unique to a small subset of pages.
Let me know if this helps,
Nick
-----Original Message-----
From: Lorrin Nelson [mailto:lhn-spam@the-fam.net]
Sent: Friday, May 16, 2003 7:15 PM
To: Struts Users Mailing List
Subject: RE: passing attributes to nested tiles
Hi Nick, thanks for advice! I was hoping it would be possible to do this
without modifying MainLayout.jsp. For some tile definitions there will
be
no "headerMessage" needed by the body tile, or there will be a different
parameter, or multiple paramters. Is there any way I can either
a) just make everything from the definition available to the
sub
tile (I guess not...)
or
b) somehow use the tiles-defs.xml to not put in a raw String
but a
HashMap of Strings so that MainLayout.jsp can just make that HashMap
available to the subtiles and I can change what's in there on definition
by
definition basis?
-Lorrin
At 04:38 PM 5/16/2003, you wrote:
>Hi Lorrin,
>
>I use a similar style of definition for placing my titles into nested
>tiles. For my messages, I make the following changes:
>1) In tiles.mainlayout:
>Add a put statement for your headingMessage attribute. For example:
> <put name="headerMessage" value="welcome.heading" />
>
>2) In MainLayout.jsp:
>Add a statement to bring the headerMessage attribute into the page
>scope:
> <tiles:useAttribute name="headerMessage" scope="request"/>
>When you insert your body attribute, "Put" the headerMessage attribute
>into the body...I don't know how to say that in a pretty way:
> <tiles:insert attribute='body'>
> <tiles:put name="headerMessage" beanName="headerMessage"
> beanScope="request"/>
> </tiles:insert>
>
>3) In your jsp that uses the attribute, all you need to do is bring the
>attribute into the page scope, and then use it.
>Bring the attribute into the page scope:
> <tiles:useAttribute name="headerMessage" scope="request"/>
>Use the attribute (note that app.title must be defined in the
properties
>file:
> <h2 class="h2_h">
> <bean:message key="app.title"/> - <bean:message
>name="headerMessage"/>
> </h2>
>
>Bonus - the cool thing: Once you "put" the attribute in your layout
jsp,
>that attribute is available to all of the other nested tiles that might
>need it, not just the next nested tile.
>
>Hope this helps,
>Nick
>
>-----Original Message-----
>From: Lorrin Nelson [mailto:lhn-spam@the-fam.net]
>Sent: Friday, May 16, 2003 4:01 PM
>To: struts-user@jakarta.apache.org
>Subject: passing attributes to nested tiles
>
>Hi - I'm confused about the proper way to get attributes from a tiles
>definition to nested tiles. My definition looks like this:
>
> <definition name="tiles.mainLayout"
>path="/private/common/MainLayout.jsp">
> <put name="menu" value="/private/common/menu.jsp"/>
> <put name="body" value="/private/common/blank.jsp" />
> </definition>
>
> <definition name="tiles.login" extends="tiles.mainLayout">
> <put name="body" value="/private/login/login.jsp" />
> <put name="headingMessage" value="welcome.heading"/>
> </definition>
>
>Inside MainLayout.jsp there is a <tiles:insert attribute='body' />
>statement.
>
>
>How do I make it so I can effectively do <bean:message
>key="welcome.heading"/> inside login.jsp but with the key being
>specified
>by the tiles "headingMessage" definition instead of hard-coded?
>
>Thanks!
>-Lorrin
>
>
>---------------------------------------------------------------------
>To unsubscribe, e-mail: struts-user-unsubscribe@jakarta.apache.org
>For additional commands, e-mail: struts-user-help@jakarta.apache.org
>
>
>---------------------------------------------------------------------
>To unsubscribe, e-mail: struts-user-unsubscribe@jakarta.apache.org
>For additional commands, e-mail: struts-user-help@jakarta.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: struts-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: struts-user-help@jakarta.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: struts-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: struts-user-help@jakarta.apache.org
RE: passing attributes to nested tiles
Posted by Lorrin Nelson <lh...@the-fam.net>.
Hi Nick, thanks for advice! I was hoping it would be possible to do this
without modifying MainLayout.jsp. For some tile definitions there will be
no "headerMessage" needed by the body tile, or there will be a different
parameter, or multiple paramters. Is there any way I can either
a) just make everything from the definition available to the sub
tile (I guess not...)
or
b) somehow use the tiles-defs.xml to not put in a raw String but a
HashMap of Strings so that MainLayout.jsp can just make that HashMap
available to the subtiles and I can change what's in there on definition by
definition basis?
-Lorrin
At 04:38 PM 5/16/2003, you wrote:
>Hi Lorrin,
>
>I use a similar style of definition for placing my titles into nested
>tiles. For my messages, I make the following changes:
>1) In tiles.mainlayout:
>Add a put statement for your headingMessage attribute. For example:
> <put name="headerMessage" value="welcome.heading" />
>
>2) In MainLayout.jsp:
>Add a statement to bring the headerMessage attribute into the page
>scope:
> <tiles:useAttribute name="headerMessage" scope="request"/>
>When you insert your body attribute, "Put" the headerMessage attribute
>into the body...I don't know how to say that in a pretty way:
> <tiles:insert attribute='body'>
> <tiles:put name="headerMessage" beanName="headerMessage"
> beanScope="request"/>
> </tiles:insert>
>
>3) In your jsp that uses the attribute, all you need to do is bring the
>attribute into the page scope, and then use it.
>Bring the attribute into the page scope:
> <tiles:useAttribute name="headerMessage" scope="request"/>
>Use the attribute (note that app.title must be defined in the properties
>file:
> <h2 class="h2_h">
> <bean:message key="app.title"/> - <bean:message
>name="headerMessage"/>
> </h2>
>
>Bonus - the cool thing: Once you "put" the attribute in your layout jsp,
>that attribute is available to all of the other nested tiles that might
>need it, not just the next nested tile.
>
>Hope this helps,
>Nick
>
>-----Original Message-----
>From: Lorrin Nelson [mailto:lhn-spam@the-fam.net]
>Sent: Friday, May 16, 2003 4:01 PM
>To: struts-user@jakarta.apache.org
>Subject: passing attributes to nested tiles
>
>Hi - I'm confused about the proper way to get attributes from a tiles
>definition to nested tiles. My definition looks like this:
>
> <definition name="tiles.mainLayout"
>path="/private/common/MainLayout.jsp">
> <put name="menu" value="/private/common/menu.jsp"/>
> <put name="body" value="/private/common/blank.jsp" />
> </definition>
>
> <definition name="tiles.login" extends="tiles.mainLayout">
> <put name="body" value="/private/login/login.jsp" />
> <put name="headingMessage" value="welcome.heading"/>
> </definition>
>
>Inside MainLayout.jsp there is a <tiles:insert attribute='body' />
>statement.
>
>
>How do I make it so I can effectively do <bean:message
>key="welcome.heading"/> inside login.jsp but with the key being
>specified
>by the tiles "headingMessage" definition instead of hard-coded?
>
>Thanks!
>-Lorrin
>
>
>---------------------------------------------------------------------
>To unsubscribe, e-mail: struts-user-unsubscribe@jakarta.apache.org
>For additional commands, e-mail: struts-user-help@jakarta.apache.org
>
>
>---------------------------------------------------------------------
>To unsubscribe, e-mail: struts-user-unsubscribe@jakarta.apache.org
>For additional commands, e-mail: struts-user-help@jakarta.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: struts-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: struts-user-help@jakarta.apache.org
RE: passing attributes to nested tiles
Posted by Nick <nm...@adelphia.net>.
Hi Lorrin,
I use a similar style of definition for placing my titles into nested
tiles. For my messages, I make the following changes:
1) In tiles.mainlayout:
Add a put statement for your headingMessage attribute. For example:
<put name="headerMessage" value="welcome.heading" />
2) In MainLayout.jsp:
Add a statement to bring the headerMessage attribute into the page
scope:
<tiles:useAttribute name="headerMessage" scope="request"/>
When you insert your body attribute, "Put" the headerMessage attribute
into the body...I don't know how to say that in a pretty way:
<tiles:insert attribute='body'>
<tiles:put name="headerMessage" beanName="headerMessage"
beanScope="request"/>
</tiles:insert>
3) In your jsp that uses the attribute, all you need to do is bring the
attribute into the page scope, and then use it.
Bring the attribute into the page scope:
<tiles:useAttribute name="headerMessage" scope="request"/>
Use the attribute (note that app.title must be defined in the properties
file:
<h2 class="h2_h">
<bean:message key="app.title"/> - <bean:message
name="headerMessage"/>
</h2>
Bonus - the cool thing: Once you "put" the attribute in your layout jsp,
that attribute is available to all of the other nested tiles that might
need it, not just the next nested tile.
Hope this helps,
Nick
-----Original Message-----
From: Lorrin Nelson [mailto:lhn-spam@the-fam.net]
Sent: Friday, May 16, 2003 4:01 PM
To: struts-user@jakarta.apache.org
Subject: passing attributes to nested tiles
Hi - I'm confused about the proper way to get attributes from a tiles
definition to nested tiles. My definition looks like this:
<definition name="tiles.mainLayout"
path="/private/common/MainLayout.jsp">
<put name="menu" value="/private/common/menu.jsp"/>
<put name="body" value="/private/common/blank.jsp" />
</definition>
<definition name="tiles.login" extends="tiles.mainLayout">
<put name="body" value="/private/login/login.jsp" />
<put name="headingMessage" value="welcome.heading"/>
</definition>
Inside MainLayout.jsp there is a <tiles:insert attribute='body' />
statement.
How do I make it so I can effectively do <bean:message
key="welcome.heading"/> inside login.jsp but with the key being
specified
by the tiles "headingMessage" definition instead of hard-coded?
Thanks!
-Lorrin
---------------------------------------------------------------------
To unsubscribe, e-mail: struts-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: struts-user-help@jakarta.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: struts-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: struts-user-help@jakarta.apache.org