commons-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Craig McClanahan <craig...@gmail.com>
Subject Re: [Digester] Parent Reference Help
Date Tue, 31 Aug 2004 00:07:24 GMT
The simplest way to address this need is to use the object stack that
Digester creates for you.  Every time you execute an Object Create
Rule, for example, the new instance gets pushed on to the stack, so
that Digester rules for nested elements can get to it easily:

    Page page = (Page) digester.peek();

There's examples of this in the "Package Documentation" part of the
Digester javadocs:

http://jakarta.apache.org/commons/digester/apidocs/org/apache/commons/digester/package-summary.html#package_description

as well as in the source code to rules like SetParentRule and
SetNextRule, which rely on exactly this capability in order to perform
their functions.

Craig

On Mon, 30 Aug 2004 20:01:02 -0400, Ken Egervari <ken@upfactor.com> wrote:
> Hi,
> 
> Is there any way to reference a parent object when parsing an XML document
> using the commons-digester component?  For example, let's assume that there
> is an addObjectCreate() rule that creates a Page object for the <page> tag
> and a SelectOne object for the <selectone> tag.  If I have the following XML
> (shown below), is there any way the reference of my Page object can be
> passed in the SelectOne object before the SelectOne's setters are called
> using a typical addSetProperties() rule?  I'm having trouble obtaining a
> reference since using addSetTop() is called after the setters are called.
> 
> This is rather inconvenient since some setters (in SelectOne for instance)
> will often need access to the parent object (the Page object in this
> instance).  In other instances, I need to traverse up the graph of objects
> to the root.  Since the parent is not defined, this is impossible.
> 
> If I cannot access the parent as the setters are being called, I'm basically
> forced to put this logic in the parent's addChild method instead where all
> the attributes have been mapped to the object's properties already, but this
> makes the object less convenient outside the digester.
> 
> <page index="2" formView="page.three.form">
> 
>       <selectone name="company.language" referenceData="languages"
> 
>             validatorId="singlereference"
> 
>             errorMessage="There are no languages in the database." />
> </page>
> 
> I'm not flooding the message with source code because I don't think it's
> required.  The specifics of the example are unimportant and I'm more
> interested in a general solution.
> 
> Thanks for helping me out and best regards,
> 
> 
> Ken Egervari
> 
>

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