> -----Original Message-----
> From: Eddie Bush [mailto:[EMAIL PROTECTED]]
> 
> 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']"/>

The [] operator in EL expects the operans, the return of getSingleItem, to
be a collection itself, though not java.util.Collection since it doesn't
specify any get methods itself.  You want to invoke a plain old method, not
a property accessor, which is not yet supported in EL, though see the JSP
2.0 spec for some interesting stuff in this direction.

> 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)

Assuming getSingle(String id) was meant to be getSingleItem to match the
example EL expression above (^; you could change the class to

        - Map getSingleItem()

Then your EL expression should work.  But this is non-obvious to anyone
other than you as the return type doesn't semantically match the method
name.  Better would be to have a getMap in addition to or in place of
getCollection--java.util.Collection does not have *any* get methods.  As you
have discovered the hard way, a JavaBean accessor cannot take *any*
arguments.

> 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).

You need a map property, basically, which you can than reference with a
String key.  Or any collection that has a get method that takes the type of
index you want to use with the [] operator in EL, number or string.

Struts indexed property support works subtly differently from the EL []
operator, which I think leads to your particular quandary, but the JSTL spec
is quite clear, here.

Thomas Gideon
Sr. Software Developer
B2eMarkets

301.230.2236  Tel.
301.230.2248  Fax.
[EMAIL PROTECTED]
www.B2eMarkets.com


--
To unsubscribe, e-mail:   <mailto:[EMAIL PROTECTED]>
For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>

Reply via email to