I've been pulling my hair out on this one for a couple of days now :)

I have an action form that needs to be able to handle a dynamic number of multiselect or checkbox fields.

Typically if I knew I only had to grab one pre-known set of values, I'd do something like

// my action form..

private String[] possibleValues;
private String[] values;

// getters and setters..

// my jsp:

<html:select multiple="3" property="values">
<html:options property="possibleValues[${idx}]"/>
</html:select>

And this works fine.

Now, the problem: how to have a variable number of these multiselect fields? My thought is that I would use a List of String[], and indexed properties on my action form, and then some EL magic in my JSP:

// my action form
private List<String[]> possibleValues;
private List<String[]> values;

public List<String> getValues(){...}
public void setValues(List<String>> {...}

// my jsp:
<c:forEach var="idx" begin="0" end="${someothernumber}">
  <html-el:select multiple="3" property="values${idx}">
    <html-el:options property="possibleValues[${idx}]"/>
  </html-el>
</c:forEach>


And using this approach, when the form first loads up, the JSP renders everything as desired. Each multiselect populates with the correct list of possible values.

The problem is that when I submit the form, Struts will only populate the first item in each multiselect. So for multiselect X, if the possible options are "one", "two", and "three", and I have "one" and "three" selected and then hit submit, struts will only save the String "one" in my List<String>.

Looking a little bit deeper, I turned on DEBUG logging for rg.apache.commons.beanutils, and found that BeanUtils was treating very differently the two scenarios:

1. For my regular String[] property, I get output like this with multiple values selected:

18:20:21,859 DEBUG [BeanUtils]   setProperty([EMAIL PROTECTED]
, singleValues, [there,woot])
18:20:21,859 DEBUG [ConvertUtils] Convert String[2] to class 'java.lang.String[]' 18:20:21,859 DEBUG [ConvertUtils] Using converter [EMAIL PROTECTED]

Which is perfect. It receives a String[] and sets the String[] property.

2. For my indexed List of String[], I get output like this, submitting multiple values for that control:

18:20:21,875 DEBUG [BeanUtils]   setProperty([EMAIL PROTECTED]
, values[0], [two,three])
18:20:21,875 DEBUG [ConvertUtils] Convert string 'two' to class '[Ljava.lang.String;' 18:20:21,875 DEBUG [ConvertUtils] Using converter [EMAIL PROTECTED]

In this case, I had selected "two" and "three" in my multiselect, but then it simply chooses the first one and converts "two" into {"two"} and sets the property.

The markup for one of the multiselects looks like this:

<select name="values[0]" multiple="multiple">
<option value="one">one</option>
<option value="two" selected="selected">two</option>
<option value="three">three</option>
<option value="four">four</option>
</select>


Is there a way to do what I am trying to do? I have tried all sorts of variations on this theme. I've used String[][] to hold my values, indexed getters and setters, to no avail. I feel like this has to be something easy that I"m missing.


thanks for any help.
Collin











---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to