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:876) 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(PropertyUtilsBean.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(PropertyUtilsBean.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.java: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(PageContextImpl.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]



Reply via email to