• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

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

 
abi chitnis
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 5575
Eclipse IDE Java Windows XP
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Welcome to the javaranch,abi chitnis . We are happy to have you here

 
David Newton
Author
Rancher
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you very much David. It solved my problem.

Abhi
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic