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/09 17:36:41 UTC

is this a struts bug?

hihi,

i have a jsp with the following:

<c:forEach var="i" begin="0" end="5">
<html-el:text name="MyObj" property="foo[${i}].bar"/>
</c:forEach>

in MyObj i have these methods:

public Collection getFoo() {
  return foo;
}

public Bar getFoo(int i) {
  while(i >= foo.size()) {
    ((ArrayList)foo).add(new Bar());
  }
  return (Bar)((ArrayList)foo).get(i);
}

when i request for the jsp, it calls the first getFoo() method.  should
it not call the second getFoo(int) method instead, since the jsp is
using jstl to provide an index parameter?

the weird part is when i take out the getFoo() method and recompile,
then the jsp calls getFoo(int) correctly.

why is the behavior like this?  is this a bug?

(when it calls the first getFoo() method i get an indexOutOfBounds
exception because my foo collection has nothing in it... i want the
collection size to be driven by the jsp page)

thanks in advance,
woodchuck


		
__________________________________
Do you Yahoo!?
Y! Messenger - Communicate in real time. Download now. 
http://messenger.yahoo.com

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


Re: is this a struts bug?

Posted by "Ruth, Brice" <br...@fiskars.com>.
Woodchuck wrote:

>hihi,
>
>i have a jsp with the following:
>
><c:forEach var="i" begin="0" end="5">
><html-el:text name="MyObj" property="foo[${i}].bar"/>
></c:forEach>
>
>in MyObj i have these methods:
>
>public Collection getFoo() {
>  return foo;
>}
>
>public Bar getFoo(int i) {
>  while(i >= foo.size()) {
>    ((ArrayList)foo).add(new Bar());
>  }
>  return (Bar)((ArrayList)foo).get(i);
>}
>
>when i request for the jsp, it calls the first getFoo() method.  should
>it not call the second getFoo(int) method instead, since the jsp is
>using jstl to provide an index parameter?
>
>the weird part is when i take out the getFoo() method and recompile,
>then the jsp calls getFoo(int) correctly.
>
>why is the behavior like this?  is this a bug?
>
>(when it calls the first getFoo() method i get an indexOutOfBounds
>exception because my foo collection has nothing in it... i want the
>collection size to be driven by the jsp page)
>
>thanks in advance,
>woodchuck
>  
>
You might take a look at the .java file your JSP is compiled into, for 
an understanding of what exactly is going on. Stepping through it in a 
debugger might help as well.

-- 
Brice Ruth, Sr. IT Analyst
Fiskars Brands Inc
http://www.fiskarsbrands.com/


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