struts-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "J.Teo" <jc...@yahoo.com>
Subject Help with BeanUtils.populate()
Date Thu, 08 Mar 2001 07:32:37 GMT

Hi,

First off, let me say that I'm not building on top of the Struts framework.
Rather, I'm leveraging the libraries and tag libraries.

I'm writing my own controller servlet and I tried to use BeanUtils to populate
my bean with:

public class MyController {
 .
 .
 .

    public static void populate(Object dobean,
                                HttpServletRequest req)
        throws IllegalAccessException,
               InvocationTargetException
    {

        Map paramMap = new Hashtable();

        Enumeration names = req.getParameterNames();

        while (names.hasMoreElements()) {
            String name, value;
           
            name = (String) names.nextElement();
            value = req.getParameter(name);
            paramMap.put(name, value);

        }

        BeanUtils.populate(dobean, paramMap);
    }
 .
 .
 .
}


And I get:


----------------------------------------
java.lang.IllegalArgumentException: argument type mismatch
        at java.lang.reflect.Method.invoke(Native Method)
        at
org.apache.struts.util.PropertyUtils.setSimpleProperty(PropertyUtils.java:825)
        at
org.apache.struts.util.PropertyUtils.setNestedProperty(PropertyUtils.java:756)
        at
org.apache.struts.util.PropertyUtils.setProperty(PropertyUtils.java:782)
        at org.apache.struts.util.BeanUtils.populate(BeanUtils.java:541)
----------------------------------------


I know building the Map just to use BeanUtils.populate() seems redundant, but
... ignore that for now.

It seems like the above would only work for bean properties of type String? But
doesn't BeanUtils.populate() claim to do the type conversion based on reflection
on the setter methods?

Is there anything in the library that can help me or do I have to write my own
populate() that handles the type conversion?

Thanks.


-jay

Mime
View raw message