You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by Niall Pemberton <ni...@blueyonder.co.uk> on 2004/10/01 01:17:40 UTC

Indexed Properties and Lazy List behaviour

I've set up this wiki page showing how to use indexed properties and
implement lazy list behaviour in an ActionForm.

http://wiki.apache.org/struts/StrutsCatalogLazyList

There are three possible solutions to lazy list beviour on that page - but
since I'm only using LazyDynaBeans myself, I would appreciate if anyone
using either the Commons Collections LazyList or hand cranked lazy lists
would take a look to see if what I posted looks right.

Niall



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


Re: Indexed Properties and Lazy List behaviour

Posted by Hubert Rabago <hr...@gmail.com>.
Cool.  I get it.  Wow.  Now that I get it, I really like it.  It's
like the dyna form bean finally caught up with the nested tags!

Thanks, Niall.

On Sat, 2 Oct 2004 00:50:14 +0100, Niall Pemberton
<ni...@blueyonder.co.uk> wrote:
> OK I think I must be spreading confusion - thats what you get, arrays of
> beans, not strings.
> 
> For LazyValidatorForm the default for an indexed property is an ArrayList of
> LazyDynaBean - and it populates the LazyDynaBean for you automatically.
> 
> For LazyDynaBean the default indexed property is an ArrayList - but it
> doesn't populate it with anything. If however you create a custom
> LazyDynaBean (like the example I gave) changing the default indexed property
> to an LazyDynaBean array then the default indexed property is an Array of
> LazyDynaBean  - populated automatically. Now you can have 1...n levels of
> indexed beans to your hearts content.
> 
> Niall
> 
> ----- Original Message -----
> From: "Hubert Rabago" <hr...@gmail.com>
> Subject: Re: Indexed Properties and Lazy List behaviour
> 
> > My understanding of the question on the user list was for a form which
> > contained an array of beans, instead of just an array of strings.  An
> > example would be a form bean containing a list/array of children, each
> > with a name, date of birth, daily allowance, etc.  If each child is a
> > dyna form, I can use FormDef for each element.
>

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


Re: Indexed Properties and Lazy List behaviour

Posted by Niall Pemberton <ni...@blueyonder.co.uk>.
OK I think I must be spreading confusion - thats what you get, arrays of
beans, not strings.

For LazyValidatorForm the default for an indexed property is an ArrayList of
LazyDynaBean - and it populates the LazyDynaBean for you automatically.

For LazyDynaBean the default indexed property is an ArrayList - but it
doesn't populate it with anything. If however you create a custom
LazyDynaBean (like the example I gave) changing the default indexed property
to an LazyDynaBean array then the default indexed property is an Array of
LazyDynaBean  - populated automatically. Now you can have 1...n levels of
indexed beans to your hearts content.

Niall

----- Original Message ----- 
From: "Hubert Rabago" <hr...@gmail.com>
Subject: Re: Indexed Properties and Lazy List behaviour

> My understanding of the question on the user list was for a form which
> contained an array of beans, instead of just an array of strings.  An
> example would be a form bean containing a list/array of children, each
> with a name, date of birth, daily allowance, etc.  If each child is a
> dyna form, I can use FormDef for each element.



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


Re: Indexed Properties and Lazy List behaviour

Posted by Hubert Rabago <hr...@gmail.com>.
Aside from form field definition, which isn't needed for a lazy form
bean, having a FormDef-backed form would take care of the
formatting/parsing of the data, even i18n.  The form definition &
validation config combo is actually just optional.

My understanding of the question on the user list was for a form which
contained an array of beans, instead of just an array of strings.  An
example would be a form bean containing a list/array of children, each
with a name, date of birth, daily allowance, etc.  If each child is a
dyna form, I can use FormDef for each element.

On Fri, 1 Oct 2004 22:35:15 +0100, Niall Pemberton
<ni...@blueyonder.co.uk> wrote:
> I believe I understand the principle of FormDef - you're combining the form
> definition with the validation rules. So is that why you want to nest
> indexed ActionForms rather than any old type of DynaBean? Are you then
> calling the validate() method on each of the indexed ActionForms?
> 
> You're right if you want a properly initialized lazy ActionForm then you
> need to go through the FormBeanConfig's createActionForm method. Having said
> that the default "indexed" property type of LazyDynaBean/LazyValdatorForm is
> an ArrayList - changing that to a LazyDynaBean[] as I showed in the
> CustomLazyBean means there is no need to then initialize that indexed
> property - its done automatically for arrays (CustomLazyBean would
> instantiate a new DynaBean and grows it accordingly).
> 
> From reading the message on the FormDef user list, then just having a
> property which is a CustomLazyBean (rather than CustomLazyBean array) sounds
> like it would work for your user - then only thing then is I don't really
> understand how that then interacts with FormDef - hence my questions at the
> top.
> 
> Sorry, should have got round to giving FormDef a go - but lifes busy :-(
> 
> Niall
> 
> 
> 
> ----- Original Message -----
> From: "Hubert Rabago" <hr...@gmail.com>
> To: "Struts Users Mailing List" <us...@struts.apache.org>
> Sent: Friday, October 01, 2004 9:43 PM
> Subject: Re: Indexed Properties and Lazy List behaviour
> 
> > But if I need it to be a DynaActionForm subclass, then I'd just use
> > LazyValidatorForm or its subclass, right?  In which case, wouldn't I
> > have to worry about it being properly initialized, as indicated in
> >
> http://struts.apache.org/userGuide/building_controller.html#dyna_action_form_classes
> > ?
> >
> > Someone asked about combining FormDef and LazyBeans to come up with a
> > form containing indexed properties.  FormDef works with
> > DynaActionForms.  If I have an array or list of dyna forms, I can use
> > FormDef with each element.  The problem is coming up with a lazy,
> > non-session-scope implementation.  I came up with the code snippet at
> > https://formdef.dev.java.net/servlets/ReadMsg?list=users&msgNo=12
> > because I assumed that in order to create a proper ActionForm, it
> > needed to go through FormBeanConfig's createActionForm.  Are lazy dyna
> > forms exempt from this requirement?
> >
> >
> > On Fri, 1 Oct 2004 21:14:25 +0100, Niall Pemberton
> > <ni...@blueyonder.co.uk> wrote:
> > > It could, although there is no need for it to be an ActionForm - could
> just
> > > be a LazyDynaBean. Having said that, you would probably want to override
> the
> > > default "indexed" type to be a LazyDynaBean array rather than ArrayList
> as
> > > LazyDynaBean doesn't populate Lists, but it does Arrays.
> > >
> > > public class CustomLazyBean extends LazyDynaBean {
> > >
> > >    public CustomLazyBean() {
> > >         super();
> > >    }
> > >
> > >   protected Object defaultIndexedProperty(String name) {
> > >        return new CustomLazyBean[0];
> > >    }
> > >
> > > }
> > >
> > > <form-bean name="skillForm"
> > >     type="org.apache.struts.validator.LazyValidatorForm>
> > >         <form-property name="skills"
> > >             type="myPackage.CustomLazyBean[]"/>
> > > </form-bean>
> > >
> > >
> > > Niall
> > >
> > >
> > >
> > > ----- Original Message -----
> > > From: "Hubert Rabago" <hr...@gmail.com>
> > > To: "Struts Users Mailing List" <us...@struts.apache.org>
> > > Sent: Friday, October 01, 2004 8:07 PM
> > > Subject: Re: Indexed Properties and Lazy List behaviour
> > >
> > > > In 2.3 of StrutsCatalogLazyList, it uses a Lazy*Form flavor to hold an
> > > > indexed property.  Can the indexed property itself an array or list of
> > > > Lazy*Form objects?
> > > >
> > > > <form-bean name="skillForm"
> > > >     type="org.apache.struts.validator.LazyValidatorForm>
> > > >         <form-property name="skills"
> > > >             type="org.apache.struts.validator.LazyValidatorForm"/>
> > > > </form-bean>
> > > >

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


Re: Indexed Properties and Lazy List behaviour

Posted by Niall Pemberton <ni...@blueyonder.co.uk>.
I believe I understand the principle of FormDef - you're combining the form
definition with the validation rules. So is that why you want to nest
indexed ActionForms rather than any old type of DynaBean? Are you then
calling the validate() method on each of the indexed ActionForms?

You're right if you want a properly initialized lazy ActionForm then you
need to go through the FormBeanConfig's createActionForm method. Having said
that the default "indexed" property type of LazyDynaBean/LazyValdatorForm is
an ArrayList - changing that to a LazyDynaBean[] as I showed in the
CustomLazyBean means there is no need to then initialize that indexed
property - its done automatically for arrays (CustomLazyBean would
instantiate a new DynaBean and grows it accordingly).

>From reading the message on the FormDef user list, then just having a
property which is a CustomLazyBean (rather than CustomLazyBean array) sounds
like it would work for your user - then only thing then is I don't really
understand how that then interacts with FormDef - hence my questions at the
top.

Sorry, should have got round to giving FormDef a go - but lifes busy :-(

Niall

----- Original Message ----- 
From: "Hubert Rabago" <hr...@gmail.com>
To: "Struts Users Mailing List" <us...@struts.apache.org>
Sent: Friday, October 01, 2004 9:43 PM
Subject: Re: Indexed Properties and Lazy List behaviour


> But if I need it to be a DynaActionForm subclass, then I'd just use
> LazyValidatorForm or its subclass, right?  In which case, wouldn't I
> have to worry about it being properly initialized, as indicated in
>
http://struts.apache.org/userGuide/building_controller.html#dyna_action_form_classes
> ?
>
> Someone asked about combining FormDef and LazyBeans to come up with a
> form containing indexed properties.  FormDef works with
> DynaActionForms.  If I have an array or list of dyna forms, I can use
> FormDef with each element.  The problem is coming up with a lazy,
> non-session-scope implementation.  I came up with the code snippet at
> https://formdef.dev.java.net/servlets/ReadMsg?list=users&msgNo=12
> because I assumed that in order to create a proper ActionForm, it
> needed to go through FormBeanConfig's createActionForm.  Are lazy dyna
> forms exempt from this requirement?
>
>
> On Fri, 1 Oct 2004 21:14:25 +0100, Niall Pemberton
> <ni...@blueyonder.co.uk> wrote:
> > It could, although there is no need for it to be an ActionForm - could
just
> > be a LazyDynaBean. Having said that, you would probably want to override
the
> > default "indexed" type to be a LazyDynaBean array rather than ArrayList
as
> > LazyDynaBean doesn't populate Lists, but it does Arrays.
> >
> > public class CustomLazyBean extends LazyDynaBean {
> >
> >    public CustomLazyBean() {
> >         super();
> >    }
> >
> >   protected Object defaultIndexedProperty(String name) {
> >        return new CustomLazyBean[0];
> >    }
> >
> > }
> >
> > <form-bean name="skillForm"
> >     type="org.apache.struts.validator.LazyValidatorForm>
> >         <form-property name="skills"
> >             type="myPackage.CustomLazyBean[]"/>
> > </form-bean>
> >
> >
> > Niall
> >
> >
> >
> > ----- Original Message -----
> > From: "Hubert Rabago" <hr...@gmail.com>
> > To: "Struts Users Mailing List" <us...@struts.apache.org>
> > Sent: Friday, October 01, 2004 8:07 PM
> > Subject: Re: Indexed Properties and Lazy List behaviour
> >
> > > In 2.3 of StrutsCatalogLazyList, it uses a Lazy*Form flavor to hold an
> > > indexed property.  Can the indexed property itself an array or list of
> > > Lazy*Form objects?
> > >
> > > <form-bean name="skillForm"
> > >     type="org.apache.struts.validator.LazyValidatorForm>
> > >         <form-property name="skills"
> > >             type="org.apache.struts.validator.LazyValidatorForm"/>
> > > </form-bean>
> > >
> > >
> > > On Fri, 1 Oct 2004 00:17:40 +0100, Niall Pemberton
> > > <ni...@blueyonder.co.uk> wrote:
> > > > I've set up this wiki page showing how to use indexed properties and
> > > > implement lazy list behaviour in an ActionForm.
> > > >
> > > > http://wiki.apache.org/struts/StrutsCatalogLazyList
> > > >
> > > > There are three possible solutions to lazy list beviour on that
page -
> > but
> > > > since I'm only using LazyDynaBeans myself, I would appreciate if
anyone
> > > > using either the Commons Collections LazyList or hand cranked lazy
lists
> > > > would take a look to see if what I posted looks right.
> > > >
> > > > Niall
> > > >
> > >
> ---------------------------------------------------------------------
> > > > To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
> > > > For additional commands, e-mail: user-help@struts.apache.org
> > > >
> > > >
> > >
> > > ---------------------------------------------------------------------
> > > To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
> > > For additional commands, e-mail: user-help@struts.apache.org
> > >
> > >
> > >
> >
> >
> >
> >
> > ---------------------------------------------------------------------
> > To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
> > For additional commands, e-mail: user-help@struts.apache.org
> >
> >
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
> For additional commands, e-mail: user-help@struts.apache.org
>
>
>



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


Re: Indexed Properties and Lazy List behaviour

Posted by Hubert Rabago <hr...@gmail.com>.
But if I need it to be a DynaActionForm subclass, then I'd just use
LazyValidatorForm or its subclass, right?  In which case, wouldn't I
have to worry about it being properly initialized, as indicated in
http://struts.apache.org/userGuide/building_controller.html#dyna_action_form_classes
?

Someone asked about combining FormDef and LazyBeans to come up with a
form containing indexed properties.  FormDef works with
DynaActionForms.  If I have an array or list of dyna forms, I can use
FormDef with each element.  The problem is coming up with a lazy,
non-session-scope implementation.  I came up with the code snippet at
https://formdef.dev.java.net/servlets/ReadMsg?list=users&msgNo=12
because I assumed that in order to create a proper ActionForm, it
needed to go through FormBeanConfig's createActionForm.  Are lazy dyna
forms exempt from this requirement?


On Fri, 1 Oct 2004 21:14:25 +0100, Niall Pemberton
<ni...@blueyonder.co.uk> wrote:
> It could, although there is no need for it to be an ActionForm - could just
> be a LazyDynaBean. Having said that, you would probably want to override the
> default "indexed" type to be a LazyDynaBean array rather than ArrayList as
> LazyDynaBean doesn't populate Lists, but it does Arrays.
> 
> public class CustomLazyBean extends LazyDynaBean {
> 
>    public CustomLazyBean() {
>         super();
>    }
> 
>   protected Object defaultIndexedProperty(String name) {
>        return new CustomLazyBean[0];
>    }
> 
> }
> 
> <form-bean name="skillForm"
>     type="org.apache.struts.validator.LazyValidatorForm>
>         <form-property name="skills"
>             type="myPackage.CustomLazyBean[]"/>
> </form-bean>
> 
> 
> Niall
> 
> 
> 
> ----- Original Message -----
> From: "Hubert Rabago" <hr...@gmail.com>
> To: "Struts Users Mailing List" <us...@struts.apache.org>
> Sent: Friday, October 01, 2004 8:07 PM
> Subject: Re: Indexed Properties and Lazy List behaviour
> 
> > In 2.3 of StrutsCatalogLazyList, it uses a Lazy*Form flavor to hold an
> > indexed property.  Can the indexed property itself an array or list of
> > Lazy*Form objects?
> >
> > <form-bean name="skillForm"
> >     type="org.apache.struts.validator.LazyValidatorForm>
> >         <form-property name="skills"
> >             type="org.apache.struts.validator.LazyValidatorForm"/>
> > </form-bean>
> >
> >
> > On Fri, 1 Oct 2004 00:17:40 +0100, Niall Pemberton
> > <ni...@blueyonder.co.uk> wrote:
> > > I've set up this wiki page showing how to use indexed properties and
> > > implement lazy list behaviour in an ActionForm.
> > >
> > > http://wiki.apache.org/struts/StrutsCatalogLazyList
> > >
> > > There are three possible solutions to lazy list beviour on that page -
> but
> > > since I'm only using LazyDynaBeans myself, I would appreciate if anyone
> > > using either the Commons Collections LazyList or hand cranked lazy lists
> > > would take a look to see if what I posted looks right.
> > >
> > > Niall
> > >
> > > ---------------------------------------------------------------------
> > > To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
> > > For additional commands, e-mail: user-help@struts.apache.org
> > >
> > >
> >
> > ---------------------------------------------------------------------
> > To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
> > For additional commands, e-mail: user-help@struts.apache.org
> >
> >
> >
> 
> 
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
> For additional commands, e-mail: user-help@struts.apache.org
> 
>

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


Re: Indexed Properties and Lazy List behaviour

Posted by Niall Pemberton <ni...@blueyonder.co.uk>.
It could, although there is no need for it to be an ActionForm - could just
be a LazyDynaBean. Having said that, you would probably want to override the
default "indexed" type to be a LazyDynaBean array rather than ArrayList as
LazyDynaBean doesn't populate Lists, but it does Arrays.

public class CustomLazyBean extends LazyDynaBean {

    public CustomLazyBean() {
         super();
    }

   protected Object defaultIndexedProperty(String name) {
        return new CustomLazyBean[0];
    }

}


 <form-bean name="skillForm"
     type="org.apache.struts.validator.LazyValidatorForm>
         <form-property name="skills"
             type="myPackage.CustomLazyBean[]"/>
 </form-bean>


Niall

----- Original Message ----- 
From: "Hubert Rabago" <hr...@gmail.com>
To: "Struts Users Mailing List" <us...@struts.apache.org>
Sent: Friday, October 01, 2004 8:07 PM
Subject: Re: Indexed Properties and Lazy List behaviour


> In 2.3 of StrutsCatalogLazyList, it uses a Lazy*Form flavor to hold an
> indexed property.  Can the indexed property itself an array or list of
> Lazy*Form objects?
>
> <form-bean name="skillForm"
>     type="org.apache.struts.validator.LazyValidatorForm>
>         <form-property name="skills"
>             type="org.apache.struts.validator.LazyValidatorForm"/>
> </form-bean>
>
>
> On Fri, 1 Oct 2004 00:17:40 +0100, Niall Pemberton
> <ni...@blueyonder.co.uk> wrote:
> > I've set up this wiki page showing how to use indexed properties and
> > implement lazy list behaviour in an ActionForm.
> >
> > http://wiki.apache.org/struts/StrutsCatalogLazyList
> >
> > There are three possible solutions to lazy list beviour on that page -
but
> > since I'm only using LazyDynaBeans myself, I would appreciate if anyone
> > using either the Commons Collections LazyList or hand cranked lazy lists
> > would take a look to see if what I posted looks right.
> >
> > Niall
> >
> > ---------------------------------------------------------------------
> > To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
> > For additional commands, e-mail: user-help@struts.apache.org
> >
> >
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
> For additional commands, e-mail: user-help@struts.apache.org
>
>
>



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


Re: Indexed Properties and Lazy List behaviour

Posted by Hubert Rabago <hr...@gmail.com>.
In 2.3 of StrutsCatalogLazyList, it uses a Lazy*Form flavor to hold an
indexed property.  Can the indexed property itself an array or list of
Lazy*Form objects?

<form-bean name="skillForm" 
    type="org.apache.struts.validator.LazyValidatorForm>
        <form-property name="skills"
            type="org.apache.struts.validator.LazyValidatorForm"/>
</form-bean>


On Fri, 1 Oct 2004 00:17:40 +0100, Niall Pemberton
<ni...@blueyonder.co.uk> wrote:
> I've set up this wiki page showing how to use indexed properties and
> implement lazy list behaviour in an ActionForm.
> 
> http://wiki.apache.org/struts/StrutsCatalogLazyList
> 
> There are three possible solutions to lazy list beviour on that page - but
> since I'm only using LazyDynaBeans myself, I would appreciate if anyone
> using either the Commons Collections LazyList or hand cranked lazy lists
> would take a look to see if what I posted looks right.
> 
> Niall
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
> For additional commands, e-mail: user-help@struts.apache.org
> 
>

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