This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach on-line!
See this thread for details.
The moose likes Struts and the fly likes Dynamic Form Elements - Exception Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "Dynamic Form Elements - Exception" Watch "Dynamic Form Elements - Exception" New topic
Author

Dynamic Form Elements - Exception

santhi deeksha
Greenhorn

Joined: Apr 02, 2010
Posts: 8
I have a form with a table which has a single row of three columns initially. I have a link which adds an extra row everytime it is clicked. Since I do not know how many might be added I used an arrayList. Here's how my JSP looks.


And this is how I am adding a row using Jquery


In my form, I wrote getter and setter for a member (of each iteration) apart from the getter and setter for the arrayList.



Now, the above code works fine if I try to add a single row and submit. But if I try to add more than one row at a time and submit, I get an IndexOutOfBoundsException. Can you please tell me what I am doing wrong and how can I fix it?
Shankar Tanikella
Ranch Hand

Joined: Jan 30, 2011
Posts: 329

can you put the log trace here


Have Fun with Java
little,little.. little by little makes a lot..
santhi deeksha
Greenhorn

Joined: Apr 02, 2010
Posts: 8
Hi Shankar, here it is. Like I mentioned earlier, I have one initial row. I added 3 more one by one. So I have 4 rows when I tried to add 2 more at once.

Shankar Tanikella
Ranch Hand

Joined: Jan 30, 2011
Posts: 329

after adding all 4 rows could you see the "view source" of the JSP and see how the elements of the document are considered.
santhi deeksha
Greenhorn

Joined: Apr 02, 2010
Posts: 8
Shankar, Yes and this is how it looks.

Tom Rispoli
Ranch Hand

Joined: Aug 29, 2008
Posts: 349
This line in your getter looks strange to me:



What is "List" and what are you trying to do with it here? Did you mean to use programmeTeamList?
santhi deeksha
Greenhorn

Joined: Apr 02, 2010
Posts: 8
Hi Tom, yes it is in fact programmeTeamList. I might have accidentally deleted it while trying to copy it over here. Sorry about that.

Shankar Tanikella
Ranch Hand

Joined: Jan 30, 2011
Posts: 329

as you say that the problem is while submitting the form, i am more interested in the setter in the form

And what is on line 102 in your form anyways?

Am I wasting your time, actually this is how i debug a problem step by step, i first check the log and the corresponding line number. if that doesn't work out then i go for view source to get the exact picture what is being considered and then if that even doesn't help i go for syso , so be it

Could you just put system out in the form for index as below

and SOP in setter as well, are you overloading the getter and setter by any chance, which version of struts are you using, just to try in my local.

santhi deeksha
Greenhorn

Joined: Apr 02, 2010
Posts: 8
Hi Shankar, I appreciate you trying to help me out. It is not a waste of my time if I am learning something :-). Thank you!

I am using Struts 1.1. Line 102 in my code is the return statement in the getter. I included the SOPs as you suggested and I did get the one in getter printed as "processing current index: 7" and my Exception reads the same index "java.lang.IndexOutOfBoundsException: Index: 7, Size: 7"
santhi deeksha
Greenhorn

Joined: Apr 02, 2010
Posts: 8
Oh and I forgot. I verified and no I am not overloading the getter or setter.
Shankar Tanikella
Ranch Hand

Joined: Jan 30, 2011
Posts: 329

Just to know i am looking into the links here and here to see where are we going wrong. It is really worth reading it once. Till now i couldn't see any problem

Interesting to know that you are getting 7 from somewhere, if i see your previous post it has index as 5 in the log? did you add anything extra?

if index is the cause, it looks like this line is the problem
Tom Rispoli
Ranch Hand

Joined: Aug 29, 2008
Posts: 349
I think the problem is that your getter method is only set up to handle the scenario where the index passed into the method will only increase your array's size by one. The problem is that the index coming in could require you to add more than one element to your list in order to make the index coming in valid. I think you need to add a loop to your getter to keep adding elements to your list until the size of the list is index + 1.
santhi deeksha
Greenhorn

Joined: Apr 02, 2010
Posts: 8
I tried the loop like Tom suggested and it worked!!! I should have thought of it! But thanks Shankar and Tom for taking the time to help me out. You guys are awesome.


Tom Rispoli
Ranch Hand

Joined: Aug 29, 2008
Posts: 349
glad to help.
Shankar Tanikella
Ranch Hand

Joined: Jan 30, 2011
Posts: 329

Perfect
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Dynamic Form Elements - Exception
 
Similar Threads
Not able to submit Ordered List even using Indexed property
Problem Passing Parameter values to action
Nested Tag (in Form of Table ) :: not able to submit masterForm
How to add new row in response page
Problem in hiding the row of data