commons-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Dion Gillard <dion.gill...@gmail.com>
Subject Re: [Digester] Problems setting a bean property
Date Thu, 30 Jun 2005 06:57:28 GMT
I'd say that's intended.

How is the Beans/Introspector supposed to know if it's a read/write
property of type String or a read-only property of type boolean?

On 6/30/05, Martin Burger <m@rtin-burger.de> wrote:
> Hello,
> 
> in a nutshell: after adding a method called "is<property name>" that
> returns a boolean value, Digester does not set the bean's property anymore.
> 
> I have the following simple XML file:
> 
>     <!DOCTYPE root>
>     <values>
>         <value>one</value>
>         <value>two</value>
>     </values>
> 
> 
> I'm using Digester to set a field in a bean "Value":
> 
>     public class Value {
> 
>         private String value;
> 
>         public String getValue() {
>             return this.value;
>         }
> 
>         public void setValue(String value) {
>             this.value = value;
>         }
>     }
> 
> 
> Calling the code
> 
>     Digester digester = new Digester();
> 
>     digester.addObjectCreate("values/value", Value.class);
>     digester.addSetNext("values/value", "add", "java.lang.Object");
>     digester.addBeanPropertySetter("values/value", "value");
> 
>     List values = new ArrayList();
>     digester.push(values);
> 
>     digester.parse(this.getClass().getResourceAsStream("data.xml"));
> 
>     Iterator iterator = values.iterator();
>     while (iterator.hasNext()) {
>         Value aValue = (Value) iterator.next();
>         System.out.println(aValue.getValue());
>     }
> 
> 
> prints "one two" to the console.
> 
> If I add a method "isValue()" to the class Value
> 
>     public boolean isValue() {
>         return this.value != null;
>     }
> 
> 
> "null null" is printed to the console.
> 
> So, after adding that method to the bean, Digester (or one of it's used
> components) does not call the method to set the field (setter) anymore.
> 
> Is this behavior intended, or is this a bug?
> 
> Regards,
>     Martin
> 
> 


-- 
http://www.multitask.com.au/people/dion/
"You are going to let the fear of poverty govern your life and your
reward will be that you will eat, but you will not live." - George
Bernard Shaw

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


Mime
View raw message