commons-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Wendy Smoak" <j...@wendysmoak.com>
Subject Re: [digester] Populating a LazyDynaBean with Digester
Date Sun, 30 Jan 2005 01:25:43 GMT
From: "Wendy Smoak" <java@wendysmoak.com>
> But what do I do with indexed properties where the call to 
> LazyDynaBean.set(name,index,value) requires an integer index?  (A person 
> may have more than one degree.)
>
>         digester.addCallMethod("download/person/degree", "set", 3);
>         digester.addObjectParam("download/person/degree", 0, "degrees");
>         //digester.addObjectParam("download/person/degree", 1, 
> ???integer??? );
>         digester.addCallParam("download/person/degree", 2);
>
> Is it possible to set indexed properties with Digester?

FTR, I solved this one with (using person/address/lines instead of 
download/person/degree):

   digester.addObjectCreate("person", LazyDynaBean.class);
   digester.addObjectCreate("person/address", ArrayList.class);
   digester.addCallMethod("person/address/line", "add", 1);
   digester.addCallParam("person/address/line", 0);
   Rule rule = new CallMethodRule(1, "set", 2);
   digester.addRule("resolution/person/address", rule);
   digester.addObjectParam("resolution/person/address", 0, "address");
   digester.addCallParam("resolution/person/address", 1, true);

This makes a LazyDynaBean for <person> and then makes an ArrayList for 
<address>.  The trick is getting it to call
     set( "address", list);
on the LazyDynaBean which is 'underneath' the ArrayList on the stack.  (I 
suppose this is not "officially" an indexed property since it's an ArrayList 
and not an Object[], but it works for me.)

The full example with more comments is here:
http://wiki.wendysmoak.com/cgi-bin/wiki.pl?DigesterLazyDynaBean

-- 
Wendy Smoak 



---------------------------------------------------------------------
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