It's related to a difference in how the HTTP request parameters are built. With the "indexed properties" that you had, the BeanUtils classes are going to look for parameters whose names include the index. That is 'bar[1]', 'bar[2]', etc.

HTML:select with multiple=true sends multiple parameters, all with the name of 'bar'. So, instead of 'bar[1]=1&bar[2]=2' the HTTP request will just be 'bar=1&bar=2'. The Java Servlet API exposes these multiple requests with the same name as a String[], or the first one as a single String.

The only time the Struts ActionForm framework is going to call an ActionForm setter 'setBar(int index, String value)' is if the request includes parameters named as in the first example. It will call the setter 'setBar(String[] values)' if it sees multiple values for the same parameter.

-- Jeff

Will Stranathan wrote:
THANKS! After all that work, I *think* BeanUtils was having issues with setNumber(int, String) for some reason - when I took out the setters for indexed values, and just have setters/getters for the arrays - it works like a champ!

Thanks a TON!

Will Stranathan

On Mon, 24 Jan 2005 15:16:55 -0600
 "Brad Balmer" <[EMAIL PROTECTED]> wrote:

I have ActionForm's that contain String array variables like:

private String[] parmTypeCd = null;

With the normal:
public String[] getParmTypeCd() {
    return parmTypeCd;
}
public void setParmTypeCd(String parmTypeCd[]) {
    this.parmTypeCd = parmTypeCd;
}

My form has:
<html:select property="parmTypeCd" multiple="true" size="3">
    <html:option value="1">Value1</html:option>
    <html:option value="2">Value2</html:option>
    ...
</html:select>

Then, underneath I build my ArrayList to pass to my iBatis query like:

ArrayList parmTypeCds = null;
if(form.getParmTypeCd() != null && form.getParmTypeCd().length > 0) {
    parmTypeCds = new ArrayList();
     String typeCds[] = form.getParmTypeCd();
     for(int i=0; i<form.getParmTypeCd().length; i++) {
         parmTypeCds.add(typeCds[i]);
       }
}

Pretty simple. There may be a better way to do it, but this works just fine
for me.


--Brad



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



Reply via email to