File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Struts and the fly likes How to access selected values of dynamically generated multi select list on jsp from action method? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "How to access selected values of dynamically generated multi select list on jsp from action method?" Watch "How to access selected values of dynamically generated multi select list on jsp from action method?" New topic
Author

How to access selected values of dynamically generated multi select list on jsp from action method?

abi chitnis
Greenhorn

Joined: Feb 13, 2009
Posts: 11
I am dynamically genearting multi select boxes on jsp. How do I access selected values in my action method when user clicks submit? Following is my jsp.
selectedValuesDropdowns is list defined in the action bean. I can get values if the drop down box is single select. But when it is multiselect I am having issues.

Any suggestions or alternate way to achieve this.

<s:form action="showquery">
<s:iterator value="lstRepositoryQueryActionBean" status="status">
<s:if test='htmlType=="TEXTBOX" '>
<s:textfield key="%{key}" name="selectedValuesBoxes" label="%{label}" size="20"/>
</s:if>
<s:else>
<s:select name="selectedValuesDropdowns" label="%{label}" list="%{optionList}"
listKey="value" listValue="description" multiple="true"
headerKey="%{headerKey}" headerValue="%{headerValue}" emptyOption="false"
value ="%{headerKey}" />

</s:iterator>
<s:submit value="Search"/>
</s:form>
Seetharaman Venkatasamy
Ranch Hand

Joined: Jan 28, 2008
Posts: 5575

Welcome to the javaranch,abi chitnis . We are happy to have you here

David Newton
Author
Rancher

Joined: Sep 29, 2008
Posts: 12617

Please put your code in code tags--it's much easier to read.

One option would be to use a map-based action property to group the values from each multi-select. The map key would be a unique ID from the lstRepositoryQueryActionBean (one should try to name collections as a plural to better identify their purpose) and the select's name would use this ID something similar to:



(I may not have the syntax quite right, but it's close :)

The action would have a Map<String, ...> selectedValuesDropdown property.

As a matter of personal opinion, I try not to name my properties/etc. in a way that reflects how they're used on the view side--in my opinion they should be named something that makes sense from the business/design side of things (and naming a bean with a suffix of "Bean" seems a little redundant :)>
abi chitnis
Greenhorn

Joined: Feb 13, 2009
Posts: 11
Thank you very much David. It solved my problem.

Abhi
 
 
subject: How to access selected values of dynamically generated multi select list on jsp from action method?