• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

dynamically loop through form parameters in servlet

 
Ranch Hand
Posts: 188
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Sheriff
Posts: 67747
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Sheriff
Posts: 67747
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Sheriff
Posts: 67747
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Anytime HTH
 
reply
    Bookmark Topic Watch Topic
  • New Topic