• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Paul Clapham
  • Ron McLeod
  • Bear Bibeault
  • Liutauras Vilda
Sheriffs:
  • Jeanne Boyarsky
  • Tim Cooke
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Tim Holloway
  • Stephan van Hulst
  • Jj Roberts
  • Carey Brown
Bartenders:
  • salvin francis
  • Frits Walraven
  • Piet Souris

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

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

 
Author
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thank you very much David. It solved my problem.

Abhi
 
Heroic work plunger man. Please allow me to introduce you to this tiny ad:
the value of filler advertising in 2020
https://coderanch.com/t/730886/filler-advertising
reply
    Bookmark Topic Watch Topic
  • New Topic