File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
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: 61190
    
  66

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]
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: naming dynamic form elements