This week's book giveaway is in the OO, Patterns, UML and Refactoring forum.
We're giving away four copies of Refactoring for Software Design Smells: Managing Technical Debt and have Girish Suryanarayana, Ganesh Samarthyam & Tushar Sharma on-line!
See this thread for details.
The moose likes JSP and the fly likes naming dynamic  form elements Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


JavaRanch » Java Forums » Java » JSP
Bookmark "naming dynamic  form elements" Watch "naming dynamic  form elements" New topic
Author

naming dynamic form elements

Rajeev Ravindran
Ranch Hand

Joined: Aug 27, 2002
Posts: 455
hi all,
i have a jsp file in which the elements (eg. textfileds) are generated dynamically..wat is the best practice to name these elelemts..
is it a good practice append an int variable to the end of the textfilds name like txtfld1, txtfld2 ??
if i name all the textfields with the same name, is there any way to get the values of each of these textfields ??
thanks
raj.


SCJP, SCWCD, SCBCD, Oracle Certified Professional (SQL n PL/SQL)
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 63208
    
  69

Yes, you can retrieve all the values if you name the fields the same by using request.getParameterValues() (rather than request.getParameter()). However, you will not be able to tell which value came from which field.
If that is an important distinction, then you will need to assign each field a unique name.
Which makes the most sense depends upon how your submission target needs to deal with the fields, which you did not discuss in your original question.
hth,
bear


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
 
Have you checked out Aspose?
 
subject: naming dynamic form elements
 
It's not a secret anymore!