You are viewing a plain text version of this content. The canonical link for it is here.
Posted to taglibs-user@tomcat.apache.org by Eddie Bush <ek...@swbell.net> on 2002/09/27 21:49:08 UTC

[JSTL] Executing arbitrary methods of beans

Hi guys - small question I haven't had much success at solving:  How 
would you do something like:

<c:set var="foo" value="${requestScope['someBean'].singleItem['foo']"/>

I have a bean which has a Collection attribute.  Some of it's methods 
include:

    - getCollection()
    - setCollection(Collection c)
    - addSingle(SingleBean sb)
    - getSingle(String id)

What I want to do is invoke getSingle.  The only way I'm able to get 
getSingle recognized is to use bean patterns 
(getSingle()/setSingle(SingleBean)).  What I am trying to do is effect a 
lookup in the Collection - but I have to manually do it (iterate over 
the collection doing comparisons).

Suggestions?  Am I missing something simple here?

Thanks!

-- 
Eddie Bush




--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>


Re: [JSTL] Executing arbitrary methods of beans

Posted by Eddie Bush <ek...@swbell.net>.
Thanks Shawn and Gideon.

I rather suspected that was how I would have to proceed, but wanted an 
official declaration of that being the way to go.  Gideon is precisely 
right about the JavaBean accessor patterns and that was what made me 
realize this probably wasn't possible.  I wanted to hear from someone I 
thought had a better understanding than myself though.  While I use the 
JSTL a lot this is the first time I've crossed this situation.

... off to refactor my class - thanks for the info :-)

Shawn Bayern wrote:

>In JSTL 1.0, you cannot execute arbitrary methods of beans.  In JSP 2.0,
>you'll be able to set up EL "functions" that let you call methods you've
>decided are appropriate for page authors.
>
>In the meantime, if you have a method like getSingle(String), you may want
>to expose it as a Map with the various potential argument strings as
>keys.  Then, you'd be able to write
>
> ${bean.single['foo']}
>
>Hope that helps,
>

-- 
Eddie Bush




--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>


Re: [JSTL] Executing arbitrary methods of beans

Posted by Shawn Bayern <ba...@essentially.net>.
In JSTL 1.0, you cannot execute arbitrary methods of beans.  In JSP 2.0,
you'll be able to set up EL "functions" that let you call methods you've
decided are appropriate for page authors.

In the meantime, if you have a method like getSingle(String), you may want
to expose it as a Map with the various potential argument strings as
keys.  Then, you'd be able to write

 ${bean.single['foo']}

Hope that helps,

-- 
Shawn Bayern
"JSTL in Action"   http://www.jstlbook.com

On Fri, 27 Sep 2002, Eddie Bush wrote:

> Hi guys - small question I haven't had much success at solving:  How 
> would you do something like:
> 
> <c:set var="foo" value="${requestScope['someBean'].singleItem['foo']"/>
> 
> I have a bean which has a Collection attribute.  Some of it's methods 
> include:
> 
>     - getCollection()
>     - setCollection(Collection c)
>     - addSingle(SingleBean sb)
>     - getSingle(String id)
> 
> What I want to do is invoke getSingle.  The only way I'm able to get 
> getSingle recognized is to use bean patterns 
> (getSingle()/setSingle(SingleBean)).  What I am trying to do is effect a 
> lookup in the Collection - but I have to manually do it (iterate over 
> the collection doing comparisons).
> 
> Suggestions?  Am I missing something simple here?
> 
> Thanks!
> 
> 


--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>