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.
And your not usinng the generics package like Will is. > > --Brad > > -----Original Message----- > From: Will Stranathan [mailto:[EMAIL PROTECTED] > Sent: Monday, January 24, 2005 3:11 PM > To: user@struts.apache.org > Subject: Select Multiple Issues > > I had posted earlier concerning this, and haven't gotten any response, > but I think it got lost in all the spirited discussions about > constants interfaces, leadership voting, etc. over the past week. > I've done a lot of searching, and AFAICT, I'm trying all the right > things, but it's still not working... > > I promise I google'd first.... > > I'm trying to use a multiple-select select box, for example: > > <html:select multiple="true" property="bar" size="5"> > <html:option value="1">One</html:option> > <html:option value="2">Two</html:option> > <html:option value="3">Three</html:option> > <html:option value="4">Four</html:option> > </html:select> > > And I've tried backing my form bean with String[] AND with an > ArrayList. > > When I try to use a String[] as the backing, the form displays, but > when I submit, I get an argument type mismatch: > > DEBUG 2005-01-19 10:51:56 > org.apache.commons.beanutils.BeanUtilsBean.setProperty(BeanUtilsBean.java:87 > 6) > setProperty([EMAIL PROTECTED], bar, [2,4,8]) > DEBUG 2005-01-19 10:51:56 > org.apache.commons.beanutils.ConvertUtilsBean.convert(ConvertUtilsBean.java: > 418) > Convert string '2' to class 'java.lang.String' > DEBUG 2005-01-19 10:51:56 > org.apache.commons.beanutils.ConvertUtilsBean.convert(ConvertUtilsBean.java: > 426) > Using converter > [EMAIL PROTECTED] > DEBUG 2005-01-19 10:51:56 > org.apache.commons.beanutils.PropertyUtilsBean.setSimpleProperty(PropertyUti > lsBean.java:1756) > setSimpleProperty: Invoking method public void > com.boa.cis.portal.forms.FooForm.setBar(java.lang.String[]) with value > 2 (class java.lang.String) > ERROR 2005-01-19 10:51:56 > org.apache.commons.beanutils.PropertyUtilsBean.invokeMethod(PropertyUtilsBea > n.java:1777) > Method invocation failed. > java.lang.IllegalArgumentException: argument type mismatch > > It looks like it's iterating through the values, calling a simple > String set on each one. > > So I tried backing with an array list, like so: > > package com.boa.cis.portal.forms; > > import java.util.ArrayList; > import org.apache.struts.action.ActionForm; > > public class FooForm extends ActionForm { > > private ArrayList<String> bar; > > public FooForm() { > bar = new ArrayList<String>(); > } > > public String getBar(int index) { > return this.bar.get(index); > } > > public String[] getBar() { > return (String[])this.bar.toArray(); > } > > public void setBar(int index, String bar) { > this.bar.set(index,bar); > } > > public void setBar(String[] bar) { > this.bar.clear(); > for (int i = 0; i < bar.length; i++) { > this.bar.set(i,bar[i]); > } > } > > public void reset(org.apache.struts.action.ActionMapping mapping, > javax.servlet.http.HttpServletRequest request) { > bar = new ArrayList<String>(); > super.reset(mapping, request); > } } > > But that won't even render the form - I get a ClassCastException: > > ERROR 2005-01-19 10:58:58 > org.apache.struts.taglib.tiles.InsertTag$InsertHandler.doEndTag(InsertTag.ja > va:918) > ServletException in 'foo.jsp': Getter for property bar threw > exception: java.lang.ClassCastException: [Ljava.lang.Object; > javax.servlet.ServletException: Getter for property bar threw > exception: java.lang.ClassCastException: [Ljava.lang.Object; > at > org.apache.jasper.runtime.PageContextImpl.doHandlePageException(PageContextI > mpl.java:825) > > I'm using Struts 1.2.6. > > From all I can tell of the error reporting, is that possibly the > Struts taglib is not using the multiple="true" property the way it > ought, so it doesn't think it's supposed to be looking for an array > type from the getter method on my form bean. > > Has anybody had any success with this? > > Thanks > Will > > --------------------------------------------------------------------- > To unsubscribe, e-mail: [EMAIL PROTECTED] > For additional commands, e-mail: [EMAIL PROTECTED] > > --------------------------------------------------------------------- > To unsubscribe, e-mail: [EMAIL PROTECTED] > For additional commands, e-mail: [EMAIL PROTECTED] > > --------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]