commons-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From gdesc...@cmhc-schl.gc.ca
Subject RE: [beanutils] Order of populate method
Date Tue, 03 Apr 2007 14:23:01 GMT
Hi Sean,

Have you had any luck with this?

- Glenn




gdeschen@cmhc-schl.gc.ca 
28/03/2007 01:48 PM
Please respond to
"Jakarta Commons Users List" <commons-user@jakarta.apache.org>


To
"Jakarta Commons Users List" <commons-user@jakarta.apache.org>
cc

Subject
RE: [beanutils] Order of populate method
Classification








Sean,

Could it be that the fix did not take into consideration nested objects?
Umh... perhaps someone else can provide more information.

- Glenn




"O'Shea, Sean" <Sean.O'Shea@fmr.com> 
28/03/2007 01:44 PM
Please respond to
"Jakarta Commons Users List" <commons-user@jakarta.apache.org>


To
<commons-user@jakarta.apache.org>
cc

Subject
RE: [beanutils] Order of populate method
Classification








Hi Glenn,

I downloaded the 1.8 snapshot version of commons-beanutils from the svn
(which should have the fix for the JIRA issue you mention below), but my
problem  remains.

Sean

-----Original Message-----
From: gdeschen@cmhc-schl.gc.ca [mailto:gdeschen@cmhc-schl.gc.ca] 
Sent: Wednesday, March 28, 2007 10:14 AM
To: Jakarta Commons Users List
Subject: Re: [beanutils] Order of populate method

Perhaps this may help:
http://issues.apache.org/jira/browse/BEANUTILS-97

- Glenn



"O'Shea, Sean" <Sean.O'Shea@fmr.com> 
28/03/2007 10:05 AM
Please respond to
"Jakarta Commons Users List" <commons-user@jakarta.apache.org>


To
<commons-user@jakarta.apache.org>
cc

Subject
[beanutils] Order of populate method
Classification








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
ActionForm
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
                 at
org.apache.commons.beanutils.PropertyUtilsBean.getPropertyDescriptor(Pro
pertyUtilsBean.java:751)
                 at
org.apache.commons.beanutils.BeanUtilsBean.setProperty(BeanUtilsBean.jav
a:937)
                 at
org.apache.commons.beanutils.BeanUtilsBean.populate(BeanUtilsBean.java:8
11)
                 at
org.apache.commons.beanutils.BeanUtils.populate(BeanUtils.java:298)

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;
            this.family = 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) names.next();
            if (name == null) {
                continue;
            }
            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
null.

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
null.

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

Cheers

Sean

---------------------------------------------------------------------
To unsubscribe, e-mail: commons-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-user-help@jakarta.apache.org





---------------------------------------------------------------------
To unsubscribe, e-mail: commons-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-user-help@jakarta.apache.org





Mime
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message