You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by Simon Kelly <ke...@ipe.fzk.de> on 2003/01/16 14:52:11 UTC

Digester getting recursive tag types.

Hi all,

I am trying to load a set of beans using the Digester.  One of the beans
(Menu) will contain beans of the same type within.  The basic layout of a
page follows with what I think is the correct way of dragging in recursive
tags (IE SubMenu is of type Menu).  Can anyone verify if this is even in the
right ball park?

Cheers

Simon.

PS
I can't run it yet cause I'm only part way through workig out how to extract
it all afterwards.

[File sample]
<WebPage>
  <Project>
    <Title/>
    <Version/>
    <Date/>
  </Project>
  <Menu>
    <Name/>
    <SubMenu>
      <Name/>
      <SubMenu/>
      <SubMenu/>
    </SubMenu>
  </Menu>
  <Frame/>
</WebPage>


[Code]
public static ActionForm createWebPageForm(String webPageResourcePath) {
        //Get the resource doc by webPageResourcePath
        InputStream xmlStream =
this.getClass().getResourceAsStream(webPageResourcePath);

        //Load FrontForm bean from the sitepage.xml config file.
        Digester digester = new Digester();
        digester.setValidating(false);

        digester.setRules(new ExtendedBaseRules());

        //Load digester with rules
        digester.addObjectCreate("WebPage", WebPage.class);

        digester.addObjectCreate("WebPage/Project", Project.class);
        digester.addBeanPropertySetter("WebPage/Project/Title", "Title");
        digester.addBeanPropertySetter("WebPage/Project/Image", "Image");
        digester.addBeanPropertySetter("WebPage/Project/Icon", "Icon");
        digester.addBeanPropertySetter("WebPage/Project/Version",
"Vesrion");
        digester.addBeanPropertySetter("WebPage/Project/Date", "Date");
        digester.addBeanPropertySetter("WebPage/Project/Home", "Home");
        digester.addBeanPropertySetter("WebPage/Project/Address",
"Address");
        digester.addSetNext("WebPage/Project", "addProject");

        digester.addObjectCreate("WebPage/Menu", Meun.class);
        digester.addBeanPropertySetter("WebPage/Meunu/*/Name", "Name");
        digester.addBeanPropertySetter("WebPage/Menu/*/MenuItem",
"MenuItem");
        digester.addBeanPropertySetter("WebPage/Menu/*/MenuReference",
"MenuReference");
        digester.addObjectCreate("WebPage/Menu/*/SubMenu", "SubMenu",
Menu.class);
        digester.addBeanPropertySetter("WebPage/Menu/*/SubMenu/Name",
"Name");
        digester.addBeanPropertySetter("WebPage/Menu/*/SubMenu/MenuItem",
"MenuItem");

digester.addBeanPropertySetter("WebPage/Menu/*/SubMenu/MenuReference",
"MenuReference");
        digester.addSetNext("WebPage/Menu/*/SubMenu", "addSubMenu");
        digester.addSetNext("WebPage/Menu", "addMenu");

        digester.addObjectCreate("WebPage/Frame", Frame.class);
        digester.addSetNext("WebPage/Frame", "addFrame");

        //Create the form from file
        return (WebPage)digester.parse(xmlStream);
    }
Institut fuer
Prozessdatenverarbeitung
und Elektronik,
Forschungszentrum Karlsruhe GmbH,
Postfach 3640,
D-76021 Karlsruhe,
Germany.

Tel: (+49)/7247 82-4042
E-mail : kelly@ipe.fzk.de


--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>


Re: Digester getting recursive tag types.

Posted by Simon Kelly <ke...@ipe.fzk.de>.
> Check out the way Struts 1.1 builds a ModuleConfig tree, and extracts it
> out, for ideas on how to handle this.

Is there anywhere I can view this without having to download the source? I'm
drastically out of disk space, and wont be able to get rid of anything for a
week at least.

Cheers

Simon




--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>


Validator can use different resource bundle?

Posted by Franco Caponi <fr...@tin.it>.
I need to use a different resource bundle in the validator.
In the struts_example i have see a bundle attribute in the field attribute
but i have not find it in the DTD and seem not work... Wath are the correct
guidelines to use resource from a specified bundle using the validator
framework?


--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>


Re: Digester getting recursive tag types.

Posted by Simon Kelly <ke...@ipe.fzk.de>.
> If you're looking at 1.1, the Digester instance is created in the
> initConfigDigester() method of ActionServlet, which delegates to the
> ConfigRuleSet class (in org.apache.struts.config) to add all of the
> detailed rules.

Sweet.  Thanks.

> Could you imagine the programming required to scan through a DOM and pull
> out all the configuration elements?  Necessity was definitely the mother
> of invention here :-).

It gives me restless nights thinking of how to pass the minor bit of
information I have.  That would have driven me insane!!


--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>


Re: Digester getting recursive tag types.

Posted by "Craig R. McClanahan" <cr...@apache.org>.

On Fri, 17 Jan 2003, Simon Kelly wrote:

> Date: Fri, 17 Jan 2003 15:11:42 +0100
> From: Simon Kelly <ke...@ipe.fzk.de>
> Reply-To: Struts Users Mailing List <st...@jakarta.apache.org>
> To: Struts Users Mailing List <st...@jakarta.apache.org>
> Subject: Re: Digester getting recursive tag types.
>
> I'm having a dig thru the source code, but I can't seem to find the tree
> building bit.  Could you tell me the class this is done in?
>

If you're looking at 1.1, the Digester instance is created in the
initConfigDigester() method of ActionServlet, which delegates to the
ConfigRuleSet class (in org.apache.struts.config) to add all of the
detailed rules.

> Cheers
>
> Simon
>
> PS
> Nice bit of coding ;-)

Could you imagine the programming required to scan through a DOM and pull
out all the configuration elements?  Necessity was definitely the mother
of invention here :-).

Craig


--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>


Re: Digester getting recursive tag types.

Posted by Simon Kelly <ke...@ipe.fzk.de>.
I'm having a dig thru the source code, but I can't seem to find the tree
building bit.  Could you tell me the class this is done in?

Cheers

Simon

PS
Nice bit of coding ;-)

----- Original Message -----
From: "Craig R. McClanahan" <cr...@apache.org>
To: "Struts Users Mailing List" <st...@jakarta.apache.org>
Sent: Thursday, January 16, 2003 7:01 PM
Subject: Re: Digester getting recursive tag types.


>
>
> On Thu, 16 Jan 2003, Simon Kelly wrote:
>
> > Date: Thu, 16 Jan 2003 14:52:11 +0100
> > From: Simon Kelly <ke...@ipe.fzk.de>
> > Reply-To: Struts Users Mailing List <st...@jakarta.apache.org>
> > To: Struts Users Mailing List <st...@jakarta.apache.org>
> > Subject: Digester getting recursive tag types.
> >
> > Hi all,
> >
> > I am trying to load a set of beans using the Digester.  One of the beans
> > (Menu) will contain beans of the same type within.  The basic layout of
a
> > page follows with what I think is the correct way of dragging in
recursive
> > tags (IE SubMenu is of type Menu).  Can anyone verify if this is even in
the
> > right ball park?
> >
>
> Two suggestions:
>
> * In your property setter rules, you'll want to specify
>   the name of the JavaBean property in lower case, not
>   capitalized.
>
> * For the recursive rule, Digester doesn't recognize
>   an asterisk in the middle.  Just simplify this to:
>   "*/SubMenu".
>
>
> > Cheers
> >
> > Simon.
> >
> > PS
> > I can't run it yet cause I'm only part way through workig out how to
extract
> > it all afterwards.
> >
>
> Check out the way Struts 1.1 builds a ModuleConfig tree, and extracts it
> out, for ideas on how to handle this.
>
> Craig
>
>
> --
> To unsubscribe, e-mail:
<ma...@jakarta.apache.org>
> For additional commands, e-mail:
<ma...@jakarta.apache.org>
>
>


--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>


Re: Digester getting recursive tag types.

Posted by "Craig R. McClanahan" <cr...@apache.org>.

On Thu, 16 Jan 2003, Simon Kelly wrote:

> Date: Thu, 16 Jan 2003 14:52:11 +0100
> From: Simon Kelly <ke...@ipe.fzk.de>
> Reply-To: Struts Users Mailing List <st...@jakarta.apache.org>
> To: Struts Users Mailing List <st...@jakarta.apache.org>
> Subject: Digester getting recursive tag types.
>
> Hi all,
>
> I am trying to load a set of beans using the Digester.  One of the beans
> (Menu) will contain beans of the same type within.  The basic layout of a
> page follows with what I think is the correct way of dragging in recursive
> tags (IE SubMenu is of type Menu).  Can anyone verify if this is even in the
> right ball park?
>

Two suggestions:

* In your property setter rules, you'll want to specify
  the name of the JavaBean property in lower case, not
  capitalized.

* For the recursive rule, Digester doesn't recognize
  an asterisk in the middle.  Just simplify this to:
  "*/SubMenu".


> Cheers
>
> Simon.
>
> PS
> I can't run it yet cause I'm only part way through workig out how to extract
> it all afterwards.
>

Check out the way Struts 1.1 builds a ModuleConfig tree, and extracts it
out, for ideas on how to handle this.

Craig


--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>