multiselect form inputs only populate first string selected
When I try to use a multiselect input (html:select multiple=true), it works fine as long as the associated property is a String[]. However, there's a situation where I have a dynamic list of form elements, each of which has its own multiselect input. So I tried changing the property to a List, but then only the first String selected on the webform is populated in the applicable List index. I threw in some debugging output in my ActionForm setter methods to try to see what was going on. In the case where I use a String[] directly, the object being set is a String[] as expected, but in the case where I wrap a List around the property, the object being set is just a String. I tried using a the Map-backed approach instead of a List, but with the same results: I only see the first item selected off the multiselect box, and never see the other strings that are selected. Has anyone encountered this problem before? Is it perhaps a bug in Struts or am I doing something wrong? -Adam - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
multiselect with a map-backed form property
I have a form with a dynamically generated list of constraints that can be turned on or off, and each constraint has a set of values associated with it. My form has two relevant fields: private String[] selectedConstraints; private Map values; public String[] getSelectedConstraints() { return selectedConstraints; } public void setSelectedConstraints(String[] selectedConstraints) { this.selectedConstraints = selectedConstraints; } public Object getValues(String key) { return values.get(key); } public void setValues(String key, Object value) { values.put(key, value); } To keep track of which values are associated with which constraint, I use the string from the selectedConstraints array as the key into the values map. My jsp page looks like this: c:forEach var=constraint items=${constraints} trtd html:multibox property=selectedConstraints c:out value=${constraint.propertyID}/ /html:multibox c:out value=${constraint.propertyName}/ /tdtd html-el:select property=values(${constraint.propertyID}) html:optionsCollection name=constraint property=allowableValues/ /html-el:select ... The above works perfectly fine as long as only want to select a single item from the select drop-down box. The problem is some of the constraints can have multiple values, so I changed the select to a multi-select: html-el:select multiple=true property=values(${constraint.propertyID}) But then the form is only ever populated with the *first* string selected from the multiselect box. Since a map can hold a String[] as easily as a String, I'm a little confused by this behavior. I tried the following things with no luck (these changes are in the struts action that forwards to the jsp above): 1) inserting an empty String array into the values map for each key in an attempt to coerce the user of String arrays 2) inserting a wrapper class into the map for each key: public class SelectedValues { private String[] selectedValues; public String[] getSelectedValues() { return selectedValues; } public void setSelectedValues(String[] selectedValues) { this.selectedValues = selectedValues; } } and I updated my jsp to: html-el:select multiple=true property=values(${constraint.propertyID}).selectedValues but that causes the following exception: javax.servlet.ServletException: BeanUtils.populate org.apache.struts.util.RequestUtils.populate(RequestUtils.java:1254) ... root cause: java.lang.IllegalArgumentException: No bean specified org.apache.commons.beanutils.PropertyUtils.getPropertyDescriptor(PropertyUtils.java:837) ... I can get the multiselect to work if I create a String array for each constraint, but that defeats the purpose since this is supposed to be dynamically generated. I'm out of ideas for other things to try with the map-backed approach. Can someone tell me what I'm doing wrong here? Thanks, Adam - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]