commons-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Simon Kitching <si...@ecnetwork.co.nz>
Subject RE: Digester selecting wrong property setter method
Date Wed, 11 Dec 2002 22:11:00 GMT
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