You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by Michael Terry <mt...@agency.com> on 2001/07/18 17:26:02 UTC

Indexed properties with multiple select options

Hi -

In my JSP I'm generating (a small unknown number) of multiselect
SELECT drop-down lists with values taken from a Hashtable containing
ArrayLists, such that each drop-down corresponds to the strings in
an ArrayList in the Hashtable:

      <% int n = 0; %>
      <logic:iterate id="attTab" name="docDefAttList" property="attTable">
        <%
          prop = "attributeKeys[" + n + "]";
          n++;
        %>
        <bean:define id="atts" name="attTab" property="value" />
        <html:select property="<%=prop %>" size="10" multiple="true" >
          <html:options collection="atts" property="docDefAttValKey" labelProperty="docDefAttValDes"/>
        </html:select>
      </logic:iterate>

In the associated form bean, I assume I need to use an ArrayList (named attList
below) which will contain the String[] arrays of selected values passed back
from my SELECTs. So I have my indexed property String[] attributeKeys with
getter and setter thus:

    public String[] getAttList(int idx) {
        return (String[])attList.get(idx);
    }

    public void setAttList(int idx, String[] keys) {
        attList.set(idx, keys);
    }

But the problem is that this collapses in BeanUtils.populate with a
type mismatch error:

  javax.servlet.ServletException: BeanUtils.populate
	at org.apache.struts.util.RequestUtils.populate(RequestUtils.java:486)
  Root cause: 
  java.lang.IllegalArgumentException: argument type mismatch
	at java.lang.reflect.Method.invoke(Native Method)
	at org.apache.struts.util.PropertyUtils.setIndexedProperty(PropertyUtils.java:688)

I'm quite new to Struts, and can't understand what I'm doing wrong!
Is it actually possible to use multiple select options with indexed
properties? Any ideas? Thanks!

Michael