RE: [Digester] How to assign from a property with aBeanPropertySetter?
Thanks, that's what was needed. I've bookmarked the source examples.
From: Simon Kitching [mailto:[hidden email]]
Sent: Thursday, June 16, 2005 1:20 AM
To: Jakarta Commons Users List
Subject: Re: [Digester] How to assign from a property with
On Thu, 2005-06-16 at 00:35 -0400, Jon Steelman wrote:
> <cardAction action="activate"/>
> Here's the code:
> digester.addBeanPropertySetter(PREFIX + "cardid",
> digester.addBeanPropertySetter(PREFIX + "locationID");
> digester.addBeanPropertySetter(PREFIX + "/merchant/merchantID");
> The ActivateResponse class basically has these properties:
> primaryAccountNumber, locationID, merchantID, & action.
> I see how I can nest the merchant/merchantID to assign a property in
> class ActivateResponse. I have another direct property in
> ActivateResponse that is the value of cardAction's action, but I don't
> know how to assign it. The following won't work:
> digester.addBeanPropertySetter(PREFIX + "/cardAction/action");
> The ActivateRespone property is at the same level as the other
> properties, cardid & locationID, but how does one set it?
You can use CallMethodRule:
digester.addCallMethod("response/cardAction", "setAction", 1);
digester.addCallParam("response/cardAction", 0, "action");
As the xml attribute name "action" matches the name of the property to
be set, you could also use SetPropertiesRule:
While the latter is shorter, the former seems more appropriate as you
are specifically grabbing the "action" attribute rather than the set of
all attributes (which just happens to be a set of one).