You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by Alix Jermyn <Al...@iconmedialab.com> on 2001/02/19 14:26:06 UTC

Problem re-populating List property from a form to a FormBean - B UG/ENHANCEMENT in ConvertUtils/BeanUtils?

There appears to by an problem populating properties which are generic
collections (as opposed to arrays) from FormBeans.

If the underlying property is an array of strings, then it is straight
forward to populate multiform boxes via the multiform tag, to and from the
corresponding property in the FormBeans via the usual struts mechanism.

However, if the property is a Collection of Strings, though the automatic
filling of the multiboxes works fine when reading data from the FormBean,
but the exception below occurs when trying to re-populate the data in the
form back to the FormBean. 

The MultiTag has the smarts to check if the property class is a collection
or an array of Strings when reading the data, however the
ConvertUtils.convert(String[], Class) method called by BeanUtils.populate
method defaults to returning an array of Strings when it doesn't recognise
the class type, and hence java.lang.IllegalArgumentException: argument type
mismatch  when trying to push the returned array into a Collection.

This could be fixed by adding some Collections (in particular a List) to the
types recognised by ConvertUtils.convert, or less preferably, 
modifying the BeanUtils.populate method.

/alix

Error: 500
Location: /projectxxx/testBriefing.do
Internal Servlet Error:
javax.servlet.ServletException: BeanUtils.populate
	at org.apache.struts.util.RequestUtils.populate(RequestUtils.java,
Compiled Code)
	at
org.apache.struts.action.ActionServlet.processPopulate(ActionServlet.java:18
18)
	at
org.apache.struts.action.ActionServlet.process(ActionServlet.java:1429)
	at
org.apache.struts.action.ActionServlet.doPost(ActionServlet.java:490)
	at javax.servlet.http.HttpServlet.service(HttpServlet.java:760)
	at javax.servlet.http.HttpServlet.service(HttpServlet.java:853)
	at
org.apache.tomcat.core.ServletWrapper.doService(ServletWrapper.java:404)
	at org.apache.tomcat.core.Handler.service(Handler.java:286)
	at
org.apache.tomcat.core.ServletWrapper.service(ServletWrapper.java:372)
	at
org.apache.tomcat.core.ContextManager.internalService(ContextManager.java:79
7)
	at
org.apache.tomcat.core.ContextManager.service(ContextManager.java:743)
	at
org.apache.tomcat.service.http.HttpConnectionHandler.processConnection(HttpC
onnectionHandler.java:210)
	at
org.apache.tomcat.service.TcpWorkerThread.runIt(PoolTcpEndpoint.java,
Compiled Code)
	at
org.apache.tomcat.util.ThreadPool$ControlRunnable.run(ThreadPool.java,
Compiled Code)
	at java.lang.Thread.run(Thread.java, Compiled Code)
Root cause: 
java.lang.IllegalArgumentException: argument type mismatch
	at java.lang.reflect.Method.invoke(Native Method)
	at
org.apache.struts.util.PropertyUtils.setSimpleProperty(PropertyUtils.java,
Compiled Code)
	at
org.apache.struts.util.PropertyUtils.setNestedProperty(PropertyUtils.java,
Compiled Code)
	at
org.apache.struts.util.PropertyUtils.setProperty(PropertyUtils.java,
Compiled Code)
	at org.apache.struts.util.BeanUtils.populate(BeanUtils.java,
Compiled Code)
	at org.apache.struts.util.RequestUtils.populate(RequestUtils.java,
Compiled Code)
	at
org.apache.struts.action.ActionServlet.processPopulate(ActionServlet.java:18
18)
	at
org.apache.struts.action.ActionServlet.process(ActionServlet.java:1429)
	at
org.apache.struts.action.ActionServlet.doPost(ActionServlet.java:490)
	at javax.servlet.http.HttpServlet.service(HttpServlet.java:760)
	at javax.servlet.http.HttpServlet.service(HttpServlet.java:853)
	at
org.apache.tomcat.core.ServletWrapper.doService(ServletWrapper.java:404)
	at org.apache.tomcat.core.Handler.service(Handler.java:286)
	at
org.apache.tomcat.core.ServletWrapper.service(ServletWrapper.java:372)
	at
org.apache.tomcat.core.ContextManager.internalService(ContextManager.java:79
7)
	at
org.apache.tomcat.core.ContextManager.service(ContextManager.java:743)
	at
org.apache.tomcat.service.http.HttpConnectionHandler.processConnection(HttpC
onnectionHandler.java:210)
	at
org.apache.tomcat.service.TcpWorkerThread.runIt(PoolTcpEndpoint.java,
Compiled Code)
	at
org.apache.tomcat.util.ThreadPool$ControlRunnable.run(ThreadPool.java,
Compiled Code)
	at java.lang.Thread.run(Thread.java, Compiled Code)