1

I am using a multi select dropdown which is populated dynamically. How do I retrieve all the selected values from the dropdown list? I am using struts and here is the code from the JSP.

<html:select= name="HForm" property="selPerson" multiple="multiple"> 
   <logic:iterate id="pplist" name="HForm" property="personList">
     <option value=<bean:write name="pplist" property="id"/>><bean:write name="pplist"     
      property="value"/></option>
    </logic:iterate> 
</html:select>

Currently I am trying to retrieve the selected values by using the below method on the form object, but this returns all the values from the dropdown. I only need the ones selected by the user.

hform.getPersonList

Form oject: HForm.java

  private List personList=new ArrayList();
  private List selPerson=new ArrayList();

I tried using hmf.getselPerson(); but this throws an error:

PropertyUtils E org.apache.commons.beanutils.PropertyUtilsBean invokeMethod Method invocation failed. java.lang.IllegalArgumentException: argument type mismatch

Hardik Mishra
  • 14,779
  • 9
  • 61
  • 96
dazzle
  • 1,346
  • 2
  • 17
  • 29

2 Answers2

2

The return type of the getSelPerson() method should be String[] for a multiselect dropdown.

jeroen_de_schutter
  • 1,843
  • 1
  • 18
  • 21
0
<html:select property="selectedOption" styleId="exemple" multiple="multiple">                 
        <html:optionsCollection property="availableOption" label="name" value="ref" />
</html:select>

very easy way...

  • selectedOption would be a string[] declared in my java form (with getter and setter)
  • availableOption would be an ArrayList of object I want to display for selection (here display name) (getter and setter need to be created also)