commons-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "YAWN,MIKE (HP-PaloAlto,ex1)" <mike.y...@hp.com>
Subject RE: Digester selecting wrong property setter method
Date Wed, 11 Dec 2002 22:41:04 GMT

OK, thanks Simon and Wendy for confirming that what I'm doing is 'breaking
the rules'.

I renamed my setter method that takes a string, so that I can specify it
explicitly using the variant of addSetProperties which allows overriding
property names.  For example:

    digester.addSetProperties("*/personInfo",
		new String[] { "preferredContact" },
		new String[] { "preferredContactString" } );

(There are actually several properties I've done this to, but one is
sufficient to illustrate the change).  Now, 'setPreferredContactString' is
invoked instead of 'setPreferredContact', and I can set the int value to the
proper enum value.

Mike

-----Original Message-----
From: Simon Kitching [mailto:simon@ecnetwork.co.nz] 
Sent: Wednesday, December 11, 2002 2:11 PM
To: Jakarta Commons Users List
Subject: RE: Digester selecting wrong property setter method


On Thu, 2002-12-12 at 10:34, Wendy Smoak wrote:
> Mike wrote:
> > How can I force Digester to select the interface I created 
> > specifically
> for its use?
> 
> I know next to nothing about this, except that I ran into a similar 
> problem with Struts, which I believe uses Digester under the covers.  
> Check the "Java Bean" spec (or whatever sets forth the rules about 
> what is and is not a bean.)  I don't think you can have overloaded 
> methods like that.  You have to pick one "type" and have a get and set 
> method for it, and nothing else. Otherwise, the code doing the 
> discovery of the methods gets confused.  At least, Struts became much 
> happier when this was the case.
> 
> I think it's selecting the set method that takes an integer because 
> that's what the matching get method returns.

I think Wendy is exactly right, and that your method names/types mean it
doesn't comply with the JavaBeans spec. This issue came up about 1 month ago
on this list.

What you can do is use Digester.addCallMethod to explicitly invoke a method
rather than relying on Digester.addSetProperties' use of introspection to
deduce the method to call.

digester.addCallMethod(
  pattern, 
  "yourMethodName", 
  1, 
  new Class[] {java.lang.String}); // I think this is the right syntax..

digester.addCallParam(
  pattern,
  0
  "tag attribute name");

This specifies the exact method to call rather than relying on the Digester
to figure it out for itself. Less convenient, but if your class doesn't
follow the Beans requirements, ....

Hope this helps,

Simon

-- 
Simon Kitching <simon@ecnetwork.co.nz>


Mime
View raw message