commons-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "O'Shea, Sean" <Sean.O'>
Subject [beanutils] Order of populate method
Date Wed, 28 Mar 2007 14:05:50 GMT
Hi all,

I'm using commons-beanutils 1.7.0 running with JDK 1.4 and I have a
requirement where I need to combine the request parameters from a
HttpServletRequest with the contents of a struts form into one big dyna
bean. Currently, my pseudocode looks like this:

1. Load variables from request into name value pairs in a Map
2. Check to see whether there is a struts ActionForm in the request
3. Use PropertyUtilsBean.describe to get the name value pairs from the
struts ActionForm and put these name value pairs into a Map
4. Combine the Map from the request with the Map from the struts
5. Call BeanUtils.populate(bean, map) on the map to get back a DynaBean

This works fine for 99% of cases. But, when the ActionForm has a nested
Object property, I get the following exception:

2007-03-13 15:37:59,316 [http-8080-Processor23] ERROR -
Servlet.service() for servlet StrutsServlet threw exception
java.lang.IllegalArgumentException: No bean specified

By nested Object property, I mean something like this:

    public class CustomFormBean extends ActionForm {

        private String ssn;

        private NestedFormProperty family;

        public CustomFormBean(String ssn, NestedFormProperty family) {
            this.ssn = ssn;
   = family;

    public class NestedFormProperty {

        private boolean hasSpouse;

        private List children;

        public NestedFormProperty(boolean hasSpouse, List children) {
            this.hasSpouse = hasSpouse;
            this.children = children;

The IllegalArgumentException is getting thrown from the following piece
of code:

        // Loop through the property name/value pairs to be set
        Iterator names = properties.keySet().iterator();
        while (names.hasNext()) {

            // Identify the property name and value(s) to be assigned
            String name = (String);
            if (name == null) {
            Object value = properties.get(name);

            // Perform the assignment for this property
            setProperty(bean, name, value);


The reason I'm getting the exception is because the bean property is

I think the bean is null because the iterator is returning a property
from the NestedFormBean before actually processing the NestedFormBean
itself. For example:

If the name variable from the iterator comes back as family.hasSpouse
before the entire NestedFormProperty bean is processed, then the bean is

What I need is some way to manipulate the way the iterator traverses the
Map of properties to ensure that nested bean properties are processed
before normal String properties.

Is there any simple way to do this?

Any help would be greatly appreciated



To unsubscribe, e-mail:
For additional commands, e-mail:

View raw message