You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by James Watkins <ja...@flare-dvd.com> on 2003/06/11 14:18:14 UTC

Scope related Vector iteration problem

Hi,
This is my first post on this list and I'm a bit of a struts newbie so I
apologise in advance if this is a stupid question.

I'm using a Vector to store a list of Project objects nested inside an
ActionForm.

A DispatchAction fills the Vector with values from a database, places the
ActionForm in request scope and forwards to a jsp.

The jsp displays the projects in a form using the <nested:iterate> tag with
checkboxes to allow the user to delete projects.
Lovely.

My problem comes when I try to submit the form.  I get the following
exception when the bean gets populated:

java.lang.ArrayIndexOutOfBoundsException: Array index out of range: 4
	at java.util.Vector.get(Vector.java:699)

The index is that of the first project with a checked box.  I don't get this
problem if I put the bean in session scope, but I'd rather not do that if I
can avoid it.

If anyone could shed any light on this, I'd be most appreciative.

James.

P.S. Sorry about the annoying disclaimer, it's a server thing.

DISCLAIMER: This message contains confidential information and is intended
for To: and Cc: (name). If you are not the intended recipient you are
notified that disclosing, copying, distributing or taking any action in
reliance on the contents of this information is strictly prohibited. E-mail
transmission cannot be guaranteed to be secure or error-free as information
could be intercepted, corrupted, lost, destroyed, arrive late or incomplete,
or contain viruses. The sender therefore does not accept liability for any
errors or omissions in the contents of this message, which arise as a result
of e-mail transmission. The content of this e-mail does not necessarily
represent the company, its policies, or views, or those of its subsidiaries.
If verification is required please request a hard-copy version.
Please note that M2 Limited monitors incoming and outgoing mail for
compliance with its email policy. This includes scanning incoming emails to
detect Viruses. 


Re: Scope related Vector iteration problem

Posted by Sandeep Takhar <sa...@yahoo.com>.
It calls the getters too...

one.two.three

on submit will call
getOne().getTwo().setThree()

sandeep
--- Gemes Tibor <ti...@i-trade.hu> wrote:
> James Watkins �rta:
> 
> >My problem comes when I try to submit the form.  I
> get the following
> >exception when the bean gets populated:
> >
> >java.lang.ArrayIndexOutOfBoundsException: Array
> index out of range: 4
> >	at java.util.Vector.get(Vector.java:699)
> >
> >The index is that of the first project with a
> checked box.  I don't get this
> >problem if I put the bean in session scope, but I'd
> rather not do that if I
> >can avoid it.
> >  
> >
> The struts framework only calls the setters, but the
> setters requires 
> the object to be present on which they are called.
> If the subbeans arent created at construction time,
> they will be null, 
> so NPE is thrown runtime.
> 
> You have 2 alternatives: store in session or
> construct all subbeans with 
> the form.
> 
> Hth,
> 
> Tib
> 
> 
> 
> 
>
---------------------------------------------------------------------
> To unsubscribe, e-mail:
> struts-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail:
> struts-user-help@jakarta.apache.org
> 


__________________________________
Do you Yahoo!?
Yahoo! Calendar - Free online calendar with sync to Outlook(TM).
http://calendar.yahoo.com

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


Re: Scope related Vector iteration problem

Posted by Gemes Tibor <ti...@i-trade.hu>.
James Watkins írta:

>My problem comes when I try to submit the form.  I get the following
>exception when the bean gets populated:
>
>java.lang.ArrayIndexOutOfBoundsException: Array index out of range: 4
>	at java.util.Vector.get(Vector.java:699)
>
>The index is that of the first project with a checked box.  I don't get this
>problem if I put the bean in session scope, but I'd rather not do that if I
>can avoid it.
>  
>
The struts framework only calls the setters, but the setters requires 
the object to be present on which they are called.
If the subbeans arent created at construction time, they will be null, 
so NPE is thrown runtime.

You have 2 alternatives: store in session or construct all subbeans with 
the form.

Hth,

Tib




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