You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by Dan Langer <dl...@targetsite.com> on 2006/07/06 02:36:56 UTC

Tiles: Passing a bean to tiles in a definition file

When invoking a tile through a JSP, one can do a 

<tiles:put name="headerInfo" beanName="gridC" beanScope="request"/>

to bring a bean named gridC into the tile (under the name headerInfo),
where said bean was defined elsewhere (with a
request.setAttribute("gridC",grid). 

How do you do this when you're using tile definitions (centralized into
one file)? This

<put name="headerInfo" beanName="gridC"/>

isn't valid within a <definition> according to the DTD.

Any ideas?

Thanks,

Dan

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org


RE: Tiles: Passing a bean to tiles in a definition file

Posted by Dan Langer <dl...@targetsite.com>.
Perhaps 'bean' is too strong a word - they'd be lists of lists, with the
idea that the table can be generated using several logic:iterate tags,
to maximize reusability. The data itself would be packaged into this
"format" in the controller, so that it could be used with this table.

-----Original Message-----
From: Monkeyden  
Sent: Thursday, July 06, 2006 1:18 PM
To: Struts Users Mailing List
Subject: Re: Tiles: Passing a bean to tiles in a definition file

When you say different beans, will they have different accessor methods?
Even if the bean has a collection, you ultimately have to call accessor
methods to build the table, save introspection.



---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org


Re: Tiles: Passing a bean to tiles in a definition file

Posted by Monkeyden <mo...@gmail.com>.
When you say different beans, will they have different accessor methods?
Even if the bean has a collection, you ultimately have to call accessor
methods to build the table, save introspection.

On 7/6/06, Dan Langer <dl...@targetsite.com> wrote:
>
> Antonio,
>
> Thanks for the suggestion. From a design POV, it seems odd that a piece
> of functionality (the beanName attribute) would be there when invoked
> one way (JSP), but not when invoked another (XML definition).
>
> Regardless of that, I'm curious about the suggestion you've made. My
> goal was to create a generic tile (to display a table), and then to pass
> it different beans depending on what data I wanted to show. I've created
> a definition for the generic one, but I can't think of how to use JSTL
> (useBean is what I assume you're suggesting) to allow me to pass the
> bean name as an "argument" to the tile when, it's defined using
> inheritance in the XML definitions file (my plan was to extend the
> generic one for each of the various types of data I was going to
> display).
>
> Thanks for your help,
>
> Dan
>
> -----Original Message-----
> From: Antonio Petrelli
>
> > How do you do this when you're using tile definitions (centralized
> into
> > one file)? This
> >
> > <put name="headerInfo" beanName="gridC"/>
> >
> > isn't valid within a <definition> according to the DTD.
> >
>
> I think you cannot do it (for now). Anyway you can use JSTL and Struts
> tags to manage bean inside your JSPs as you do in JSPs without Tiles.
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
> For additional commands, e-mail: user-help@struts.apache.org
>
>

RE: Tiles: Passing a bean to tiles in a definition file

Posted by Dan Langer <dl...@targetsite.com>.

-----Original Message-----
From: Antonio Petrelli 

I agree with you, I think that this functionality isn't there for 
technical reasons, simply because Tiles definitions, when they are 
loaded, don't know about page scopes, that is needed to resolve beans.
Why don't you open a bug ticket for that?

>> Will do. Thanks for the technical reasons behind it not working.

In fact, I meant that you would put, for example, your bean in request 
scope from your action class and then read it the usual way (with 
<c:out>, <html:text> etc.).

>> I don't think this will do it, as I'm looking to create a reusable
component that will often be used several times on one page. If I
hardcode the bean name in the component (which I would have to do to get
at it with <c:out>), then I won't be able to have different instances of
the component reading from different beans. 

Thanks,

Dan

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org


Re: Tiles: Passing a bean to tiles in a definition file

Posted by Antonio Petrelli <br...@tariffenet.it>.
Dan Langer ha scritto:
> From a design POV, it seems odd that a piece
> of functionality (the beanName attribute) would be there when invoked
> one way (JSP), but not when invoked another (XML definition).
>   

I agree with you, I think that this functionality isn't there for 
technical reasons, simply because Tiles definitions, when they are 
loaded, don't know about page scopes, that is needed to resolve beans.
Why don't you open a bug ticket for that?

> My goal was to create a generic tile (to display a table), and then to pass
> it different beans depending on what data I wanted to show. I've created
> a definition for the generic one, but I can't think of how to use JSTL
> (useBean is what I assume you're suggesting) to allow me to pass the
> bean name as an "argument" to the tile when, it's defined using
> inheritance in the XML definitions file (my plan was to extend the
> generic one for each of the various types of data I was going to
> display).
>   

In fact, I meant that you would put, for example, your bean in request 
scope from your action class and then read it the usual way (with 
<c:out>, <html:text> etc.).
Does it solve your problem? Or do you need something different to 
accomplish your needs?

HTH
Antonio


---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org


RE: Tiles: Passing a bean to tiles in a definition file

Posted by Dan Langer <dl...@targetsite.com>.
Antonio,

Thanks for the suggestion. From a design POV, it seems odd that a piece
of functionality (the beanName attribute) would be there when invoked
one way (JSP), but not when invoked another (XML definition).

Regardless of that, I'm curious about the suggestion you've made. My
goal was to create a generic tile (to display a table), and then to pass
it different beans depending on what data I wanted to show. I've created
a definition for the generic one, but I can't think of how to use JSTL
(useBean is what I assume you're suggesting) to allow me to pass the
bean name as an "argument" to the tile when, it's defined using
inheritance in the XML definitions file (my plan was to extend the
generic one for each of the various types of data I was going to
display).

Thanks for your help,

Dan

-----Original Message-----
From: Antonio Petrelli 

> How do you do this when you're using tile definitions (centralized
into
> one file)? This
>
> <put name="headerInfo" beanName="gridC"/>
>
> isn't valid within a <definition> according to the DTD.
>   

I think you cannot do it (for now). Anyway you can use JSTL and Struts 
tags to manage bean inside your JSPs as you do in JSPs without Tiles.


---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org


Re: Tiles: Passing a bean to tiles in a definition file

Posted by Antonio Petrelli <br...@tariffenet.it>.
Dan Langer ha scritto:
> When invoking a tile through a JSP, one can do a 
>
> <tiles:put name="headerInfo" beanName="gridC" beanScope="request"/>
>
> to bring a bean named gridC into the tile (under the name headerInfo),
> where said bean was defined elsewhere (with a
> request.setAttribute("gridC",grid). 
>   

Here is what beanName and beanScope attributes are for!

> How do you do this when you're using tile definitions (centralized into
> one file)? This
>
> <put name="headerInfo" beanName="gridC"/>
>
> isn't valid within a <definition> according to the DTD.
>   

I think you cannot do it (for now). Anyway you can use JSTL and Struts 
tags to manage bean inside your JSPs as you do in JSPs without Tiles.
HTH
Antonio

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org