Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Cloud/Virtualization forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Getting values of dynamically created text fields

 
Vijaishanker bala
Ranch Hand
Posts: 82
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
In a web application of mine, I am having a form and in that form, textfields(<input type "text"> are created dynamically based on parameters passed from another program. The user fills in values. The common thing among these textfields are they have their names starting with "tfDyn". After the user fills in values, and on submission of the form a servlet is called that is supposed to do some processing based upon the submitted form. My question is,in the servlet, is it possible to get the names and values of the textfields, those that were generated at runtime... if yes, how..or else is there any other way to achieve the same..

Thanks

Vijai
 
aslam parveez
Ranch Hand
Posts: 47
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator


Perhaps this is what you are looking for where paramName should be the the name of your text field in the HTML form. Remember to give the same name to all the textFields what ever the number you have dynamically created.
 
Vijaishanker bala
Ranch Hand
Posts: 82
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Aslam
But if I give all the text fields the same name, I wont be able to sort out which value belongs to which text field, since they are unique values which need to processed uniquely,depending on the name of the textfield. I am trying my luck right now, with
request.getParameterMap() on this one.

Vijai
 
William Brogden
Author and all-around good cowpoke
Rancher
Posts: 13056
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If you are generating the parameter names, why not remember them in the session as they are being written to the form?
 
aslam parveez
Ranch Hand
Posts: 47
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator


Probably helps...
 
Vijaishanker bala
Ranch Hand
Posts: 82
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Aslam,

the code snippet you provided worked like a charm. Have used it in my application.

Thanks

Vijai
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic