You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by Woodchuck <wo...@yahoo.com> on 2004/08/30 16:56:28 UTC

jstl collection evaluation

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


		
__________________________________
Do you Yahoo!?
Yahoo! Mail Address AutoComplete - You start. We finish.
http://promotions.yahoo.com/new_mail 

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


Re: jstl collection evaluation

Posted by Kris Schneider <kr...@dotech.com>.
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 <wo...@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 <kr...@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 <wo...@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 <ma...@dotech.com>
> > D.O.Tech       <http://www.dotech.com/>

-- 
Kris Schneider <ma...@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


Re: jstl collection evaluation

Posted by Woodchuck <wo...@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 <kr...@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 <wo...@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 <ma...@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
> 
> 



		
__________________________________
Do you Yahoo!?
Take Yahoo! Mail with you! Get it on your mobile phone.
http://mobile.yahoo.com/maildemo 

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


Re: jstl collection evaluation

Posted by Kris Schneider <kr...@dotech.com>.
>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 <wo...@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 <ma...@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