You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@commons.apache.org by Wendy Smoak <We...@asu.edu> on 2005/01/07 18:17:06 UTC

[digester] help with digester rules

I've only used Digester as a part of Struts, but now I'm trying a simple
standalone example.

I have this XML:
<person key="012456">
  <preferredName>Ms. Janice D. Jones</preferredName>
</person>

And I'm getting the object created and the key set, but none of the
examples I can find shows a property(?) nested immediately within the
object, it's always Catalog->Magazine->title so that you're setting
properties on a child object, then adding the child object to the
parent.

Here's the rules.xml file I'm  using:

<digester-rules>
   <object-create-rule pattern="person"
           classname="edu.asu.vpia.dto.custom.PersonViewImpl" />
   <set-properties-rule pattern="person" >
      <alias attr-name="key" prop-name="key" />
   </set-properties-rule>

   <pattern value="person/preferredName">
      <call-method-rule pattern="preferredName" 
           methodname="setPreferredName" paramcount="0" />
   </pattern>
</digester-rules>

What should the rule be so that it will call setPreferredName directly
on the PersonView object?

Thanks,
-- 
Wendy Smoak

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


Re: [digester] help with digester rules

Posted by Wendy Smoak <ja...@wendysmoak.com>.
Since set-nested-properties-rule doesn't seem to exist (??) for the xml
rules, I need to set each nested property individually.  It works if I do:

<call-method-rule pattern="preferredName" methodname="setPreferredName"
paramcount="0" />

But shouldn't this work as well?

<bean-property-setter-rule pattern="preferredName"
propertyname="preferredName"/>

Am I using it incorrectly?

Example xml is the same:
<person key="012456">
  <preferredName>Ms. Janice D. Jones</preferredName>
</person>

And the working rules:
<digester-rules>
   <pattern value="person">
     <object-create-rule classname="edu.asu.vpia.dto.BenWebUserImpl" />
      <call-method-rule pattern="preferredName"
                           methodname="setPreferredName" paramcount="0" />
   </pattern>
</digester-rules>

-- 
Wendy Smoak


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


Re: [digester] help with digester rules

Posted by Wendy Smoak <ja...@wendysmoak.com>.
From: "Hubert Rabago" <hr...@gmail.com>

> > Since SetNestedPropertiesRule is new with 1.6, has it just not been
added to
> > the xml rules yet?
>
> Oops, yeah, it looks that way.  The dtd for the digester rules file
> doesn't carry that element.  I checked, and it looks like even the
> nightly build doesn't have it yet.

I put in an enhancement request and attached a patch to allow this in xml
rules:

<set-nested-properties-rule  allow-unknown-child-elements="true" />

http://issues.apache.org/bugzilla/show_bug.cgi?id=33001

My first patch. :)  It doesn't handle the nested <alias> tags yet, however.
I just now figured that part out, but I'll have to wait until I get home to
work on it.

-- 
Wendy Smoak


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


Re: [digester] help with digester rules

Posted by Hubert Rabago <hr...@gmail.com>.
On Fri, 07 Jan 2005 11:49:25 -0700, Wendy Smoak <ja...@wendysmoak.com> wrote:
> Since SetNestedPropertiesRule is new with 1.6, has it just not been added to
> the xml rules yet?

Oops, yeah, it looks that way.  The dtd for the digester rules file
doesn't carry that element.  I checked, and it looks like even the
nightly build doesn't have it yet.

Sorry.

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


Re: [digester] help with digester rules

Posted by Wendy Smoak <ja...@wendysmoak.com>.
From: "Hubert Rabago" <hr...@gmail.com>
> Take a look at the setNestedProperties rule.  I believe this sets
> properties from nested elements, like your preferredName.

Thank you. SetNestedPropertiesRule looks *very* useful, unfortunately, I
can't find any documentation on how to write the rules xml file to make it
happen.  I'm working from a couple of articles with examples that Google
turned up, but neither of them uses it.

On the off chance that since <set-properties-rule/> works, I tried
<set-nested-properties-rule/>, but no such luck.  There is nothing about
nested properties in digester-rules.dtd. :/

Since SetNestedPropertiesRule is new with 1.6, has it just not been added to
the xml rules yet?

Thanks,
Wendy Smoak


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


Re: [digester] help with digester rules

Posted by Hubert Rabago <hr...@gmail.com>.
Wendy,

Take a look at the setNestedProperties rule.  I believe this sets
properties from nested elements, like your preferredName.

Also, though I haven't used the rules.xml style of specifying rules
(cause I have custom rules that aren't supported), I'm pretty sure
that if your attr name and prop name are the same, you don't need to
list them when you use the setProperties rule.

hth,
Hubert


On Fri, 07 Jan 2005 10:17:06 -0700, Wendy Smoak <We...@asu.edu> wrote:
> 
> I've only used Digester as a part of Struts, but now I'm trying a simple
> standalone example.
> 
> I have this XML:
> <person key="012456">
>   <preferredName>Ms. Janice D. Jones</preferredName>
> </person>
> 
> And I'm getting the object created and the key set, but none of the
> examples I can find shows a property(?) nested immediately within the
> object, it's always Catalog->Magazine->title so that you're setting
> properties on a child object, then adding the child object to the
> parent.
> 
> Here's the rules.xml file I'm  using:
> 
> <digester-rules>
>    <object-create-rule pattern="person"
>            classname="edu.asu.vpia.dto.custom.PersonViewImpl" />
>    <set-properties-rule pattern="person" >
>       <alias attr-name="key" prop-name="key" />
>    </set-properties-rule>
> 
>    <pattern value="person/preferredName">
>       <call-method-rule pattern="preferredName"
>            methodname="setPreferredName" paramcount="0" />
>    </pattern>
> </digester-rules>
> 
> What should the rule be so that it will call setPreferredName directly
> on the PersonView object?
> 
> Thanks,
> --
> Wendy Smoak
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: commons-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: commons-user-help@jakarta.apache.org
> 
>

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