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.
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.
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.
If they are dynamically generated, couldn't you give them dynamic names?
Joined: Sep 18, 2005
Thanks for your reply. As mentioned, can give dynamic names to the select boxes as "listbox_name", "listbox_name" 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" 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).