You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@commons.apache.org by Kenneth Stout <ke...@comcast.net> on 2003/07/02 17:57:59 UTC

[beanutils] not finding the setter

Hi all.

I've been running into a problem that appears to be in how beanutils is
dealing with information returned from java.beans.Introspector.

I've created a bean that is similar to the following:

public class SampleBean {
    private String bound;
    public void setBound(String bound) { this.bound = bound; }
    public String getBound() { return bound; }
    public boolean isBound() { return Utils.toBoolean(bound); }
}

When I use digester to populate the bean the setBound is never called and
the information is lost. Looking in the log file I find that beanutils says
"Skipping read-only property". If I remove the isBound method everything
works just fine. If I leave the isBound and remove the getBound method
beanutils gets upset as "get" is hardcoded and does not accept the "is" form
of a getter.

It appears that java.beans.Introspector is returning three descriptors and
beanutils can only deal with two descriptors and therefore misses the
setter. This is my impression. I was very frustrated by this time, however
it appears that beanutils is hardcode for position 1 and 2 in the
Introspector array to find the getter and setter.

I've checked version 1.6.1, 1.5, and 1.4 with the same results.

Have I missed something?

Thanks,
Kenneth.



Re: [beanutils] not finding the setter

Posted by José Antonio Pérez Testa <ja...@indra.es>.
    // Since there can be multiple setter methods but only one getter
    // method, find the getter method first so that you know what the
    // property type is.  For booleans, there can be "is" and "get"
    // methods.  If an "is" method exists, this is the official
    // reader method so look for this one first.

 From PropertyDescriptor once again.
If there is an "is" method it is assumed to be the official reader 
method, so the property type is
assumed to be 'boolean'.
There is a misunderstanding in the writer method because its property 
type is String.

You should consider renaming isBound() to something like isValueBound()

Kenneth Stout wrote:

>Hi all.
>
>I've been running into a problem that appears to be in how beanutils is
>dealing with information returned from java.beans.Introspector.
>
>I've created a bean that is similar to the following:
>
>public class SampleBean {
>    private String bound;
>    public void setBound(String bound) { this.bound = bound; }
>    public String getBound() { return bound; }
>    public boolean isBound() { return Utils.toBoolean(bound); }
>}
>
>When I use digester to populate the bean the setBound is never called and
>the information is lost. Looking in the log file I find that beanutils says
>"Skipping read-only property". If I remove the isBound method everything
>works just fine. If I leave the isBound and remove the getBound method
>beanutils gets upset as "get" is hardcoded and does not accept the "is" form
>of a getter.
>
>It appears that java.beans.Introspector is returning three descriptors and
>beanutils can only deal with two descriptors and therefore misses the
>setter. This is my impression. I was very frustrated by this time, however
>it appears that beanutils is hardcode for position 1 and 2 in the
>Introspector array to find the getter and setter.
>
>I've checked version 1.6.1, 1.5, and 1.4 with the same results.
>
>Have I missed something?
>
>Thanks,
>Kenneth.
>
>
>
>---------------------------------------------------------------------
>To unsubscribe, e-mail: commons-user-unsubscribe@jakarta.apache.org
>For additional commands, e-mail: commons-user-help@jakarta.apache.org
>
>  
>


Re: [beanutils] not finding the setter

Posted by José Antonio Pérez Testa <ja...@indra.es>.
Taken from java.beans.PropertyDescriptor  javadoc:
    /**
     * Constructs a PropertyDescriptor for a property that follows
     * the standard Java convention by having getFoo and setFoo
     * accessor methods.  Thus if the argument name is "fred", it will
     * assume that the writer method is "setFred" and the reader method
     * is "getFred" (or "isFred" for a boolean property).  Note that the
     * property name should start with a lower case character, which will
     * be capitalized in the method names.
     * .....

it seems to be a problem of  your bean. It not follows Java convention 
when you remove the isBound method!

Kenneth Stout wrote:

>Hi all.
>
>I've been running into a problem that appears to be in how beanutils is
>dealing with information returned from java.beans.Introspector.
>
>I've created a bean that is similar to the following:
>
>public class SampleBean {
>    private String bound;
>    public void setBound(String bound) { this.bound = bound; }
>    public String getBound() { return bound; }
>    public boolean isBound() { return Utils.toBoolean(bound); }
>}
>
>When I use digester to populate the bean the setBound is never called and
>the information is lost. Looking in the log file I find that beanutils says
>"Skipping read-only property". If I remove the isBound method everything
>works just fine. If I leave the isBound and remove the getBound method
>beanutils gets upset as "get" is hardcoded and does not accept the "is" form
>of a getter.
>
>It appears that java.beans.Introspector is returning three descriptors and
>beanutils can only deal with two descriptors and therefore misses the
>setter. This is my impression. I was very frustrated by this time, however
>it appears that beanutils is hardcode for position 1 and 2 in the
>Introspector array to find the getter and setter.
>
>I've checked version 1.6.1, 1.5, and 1.4 with the same results.
>
>Have I missed something?
>
>Thanks,
>Kenneth.
>
>
>
>---------------------------------------------------------------------
>To unsubscribe, e-mail: commons-user-unsubscribe@jakarta.apache.org
>For additional commands, e-mail: commons-user-help@jakarta.apache.org
>
>  
>