struts-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Kris Schneider <k...@dotech.com>
Subject Re: jstl collection evaluation
Date Mon, 30 Aug 2004 18:09:11 GMT
What you're seeing is one of the differences between JSTL EL and Commons
BeanUtils. Under the covers, Struts will use BeanUtils to evaluate "foo[0].bar"
for the bean stored under the name "MyObj". See:

http://jakarta.apache.org/commons/beanutils/commons-beanutils-1.6.1/docs/api/org/apache/commons/beanutils/package-summary.html

for the gory details.

Quoting Woodchuck <woodchuck_5@yahoo.com>:

> thanks for the explanation, Kris!
> 
> the reason i find it a bit odd is because the following works:
> 
> <c:forEach var="i" begin="0" end="5">
> <html-el:text name="MyObj" property="foo[${i}].bar"/>
> </c:forEach>
> 
> with the function in MyObj defined as:
> 
> public Foo getFoo(int i)
> {
>   return (Foo)foo.get(i);
> }
> 
> given the above fact, then i was scratching my head on why the
> following didn't work (ie. produced "Unable to find.. using '.'
> operator" error):
> 
> <c:forEach var="i" begin="0" end="5">
> <c:out value="${MyObj.foo[i].bar}" />
> </c:forEach>
> 
> the above did not work UNLESS i defined the following function:
> 
> public Collection getFoo()
> {
>   return foo; // an ArrayList full of Foo objects
> }
> 
> in this case, is it the Struts-EL tag that is misguiding/spoiling me as
> to how the collection index operator "[]" really works in EL?
> 
> 
> 
> 
> 
> --- Kris Schneider <kris@dotech.com> wrote:
> 
> > From a pure JavaBeans perspective, the method:
> > 
> > public Foo getFoo(int i)
> > {
> >   return (Foo)foo.get(i);
> > }
> > 
> > nicely defines an indexed read method for the "foo" property.
> > However, I believe
> > the JSTL EL falls a bit short in dealing with it as such. Basically,
> > EL
> > evaluation will fail when a read method for the *simple* property
> > "foo" cannot
> > be found. For this to work, EL evaluation would have to recognize
> > that the
> > "foo" propery has an indexed read method and that it should attempt
> > to use the
> > following "[]" operator to provide an index value.
> > 
> > Quoting Woodchuck <woodchuck_5@yahoo.com>:
> > 
> > > i have the following on my jsp:
> > > 
> > > <c:forEach var="i" begin="0" end="5">
> > > <c:out value="${MyObj.foo[i].bar}" />
> > > </c:forEach>
> > > 
> > > for the above to work, MyObj needs to have the following function
> > > defined:
> > > 
> > > public Collection getFoo()
> > > {
> > >   return foo; // an ArrayList full of Foo objects
> > > }
> > > 
> > > however, shouldn't the function be this instead?:
> > > 
> > > public Foo getFoo(int i)
> > > {
> > >   return (Foo)foo.get(i);
> > > }
> > > 
> > > does anyone know how to make the JSTL evaluate using the latter
> > > function definition?
> > > 
> > > thanks in advance,
> > > woodchuck
> > 
> > -- 
> > Kris Schneider <mailto:kris@dotech.com>
> > D.O.Tech       <http://www.dotech.com/>

-- 
Kris Schneider <mailto:kris@dotech.com>
D.O.Tech       <http://www.dotech.com/>

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


Mime
View raw message