• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

dynamically loop through form parameters in servlet

 
John Schretz
Ranch Hand
Posts: 188
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have a html table that has 4 columns. This table is built from the database and can have any number of rows. For the first column of every row there is a check box. What I need to do is when this form gets posted to my servlet i need to loop though and get the parameters for each row of the table and update the corresponding row in my database. Below is the form i am using. I am not sure the best way to do this in the servlet and i am looking for some direction. Also does each of the rows components have to have a different name?



Servlet attempt
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64618
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If you name all the fields the same, you can get an array of the values with request.getParameterValues(), but how would tell which belongs to which row? Order is not guaranteed.

Is the vCode value unique to each row? If so, you could incorporate it into the names used on that row.
 
John Schretz
Ranch Hand
Posts: 188
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
yes vCode is unique. Should i also put id's on the form fields and have them with unique values or do i not even need the id's?
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64618
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
id's are for client-side code. If you don't need to refer to the elements in JavaScript code, id's are not needed.
 
John Schretz
Ranch Hand
Posts: 188
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
With the help of Bear

thank you Bear.

If any one is having the same problem this was my resolution:
Should anyone see that it can be improved in any way please post a response
all my fields were named the same with the vendorcode appended on the end to diferentiate the rows.

Form:


Servlet:


[ October 26, 2008: Message edited by: John Schretz ]
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64618
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for posting back your solution! It's sure to help future posters running into similar needs.
 
John Schretz
Ranch Hand
Posts: 188
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Anytime HTH
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic