This week's book giveaway is in the Clojure forum.
We're giving away four copies of Clojure in Action and have Amit Rathore and Francis Avila on-line!
See this thread for details.
Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

"Select Boxes" - Same Name

 
Sam Ferns
Greenhorn
Posts: 10
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Guys !

Having issues with select boxes with same names. Generally, if other HTML components are of the same name on the same page then, they are processed as an "array". Thus, two "firstname" text boxes would be processed as an array of "firstname" having size=2. However, when the select box is used with same names then, as usual an array is created but, this time the array contains the selected elements in both the select boxes(all in the same array). How should selected elements from the first list box be retreived, now that all the selected elements of the first list box and second list box are all contained in the "single array". How should i go about ? Please suggest.

Thank You.

Cheers,
Sam
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64188
83
IntelliJ IDE Java jQuery Mac Mac OS X
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
When you name the elements with the same name, they are logically considered a single element from the point of view of the server. Thus, the array of values that you receive from request.getParameterValues() will be the union of the selections from the elements. There is no way to determine which selections came from which element.

If that's not the behavior you want, name the select elements differently.
 
Sam Ferns
Greenhorn
Posts: 10
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi !

Thanks for your inputs. Please confirm if i get you right. What you are saying is that it is not possible to extract an array(representing an "individual" list box selected items) from an array(which represents all the list boxes with same names on the page). Basically, what i have here are multiple dynamically generated rows wherein each row represents a user details along with a select box indicating the users assigned roles. These roles are to be edited for multiple users at a time and submitted to the server for processing. Kindly, please let me know if such type of functionality is possible.

Thanks a lot.

Cheers,
Sam
 
Eric Pascarello
author
Rancher
Posts: 15385
6
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If they are dynamically generated, couldn't you give them dynamic names?

Eric
 
Sam Ferns
Greenhorn
Posts: 10
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi !

Thanks for your reply. As mentioned, can give dynamic names to the select boxes as "listbox_name[0]", "listbox_name[1]" and so on. But, how should this component be defined in struts action form class. I tried dynamically assigning names as described above but, when the items are selected from say "listbox_name[0]" then even though multiple items may be selected from this particular list box, the server shows on the 1st. selected items from this list box(not all the selected items).

Kindly please suggest !

Cheers,
Savio
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic