You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by hemant <ya...@softhome.net> on 2002/07/22 14:59:15 UTC

Wrapping Collections in LazyList to auto-populate form on Submit

Comrades,



Objective: To autopopulate forms on submit. The formbean "has a" collection of collections of ValueObjects. Each valueObject contains a pair of other Value Objects.

Before people beat me up,  The following possibilities have been dealt with:

1>> No, this is not a case of reset() I have the collections initialized and things are fine. 

2>> It is not a case of bean being in request scope. By default the bean is in session scope (Unless we explicitly mention the action attribute that it is request scope.)

When asked about why the nested beans were not dynamically populated even though the getter() methods are beling called, Nesting and Recursion Guru Arron Bates said the following:

<quote>

FYI
This isn't a "nested tags" issue at all, but a nested bean-in-a-list

issue which Struts had a long time before I wrote the nested tags.

They're only guilty of making something quite complex very easy to do.

:)

Wrap your collections in org.apache.commons.collections.LazyList,

provide a class definition of your child bean and it'll be sweet and

ready to do without any other effort, even in the reset() method.

</quote>



So without wasting anytime, I downloaded the nightly build and incorporated it into my IDE. I still seem to be missing something. 

I wrote a simple method to "test" the wrapping. I get the following...

<trace>

java.lang.IllegalArgumentException: Null property value for 'wrappedCollections[0]'
	java.lang.Throwable(java.lang.String)
	java.lang.Exception(java.lang.String)
	java.lang.RuntimeException(java.lang.String)
	java.lang.IllegalArgumentException(java.lang.String)
	java.lang.Object org.apache.commons.beanutils.PropertyUtils.getNestedProperty(java.lang.Object, java.lang.String)
	java.lang.Object org.apache.commons.beanutils.PropertyUtils.getProperty(java.lang.Object, java.lang.String)
	java.lang.Object org.apache.struts.util.RequestUtils.lookup(javax.servlet.jsp.PageContext, java.lang.String, java.lang.String, java.lang.String)
	int org.apache.struts.taglib.logic.IterateTag.doStartTag()

</trace>

<jspSnippet>
<nested:iterate id="voPairCollectionHolder" property="wrappedCollections" name="rangesform"  type="com.xxx.operations.mplanning.mpi.util.VoPairCollectionHolder">

 <nested:iterate id="vopair" name="voPairCollectionHolder" property="voPairs" type="com.xxx.operations.mplanning.mpi.util.ValueObjectPair">

    .........................
    .................................

<nested:write name="vopair"  property="twVo.objectType"/> - <nested:write name="vopair" property="twVo.description"/>


</jspSnippet>





public java.util.Collection generateWrappedCollection()
{
    if (null != this.collectionOfCollectionsOfVoPairs)
        {


        ArrayList list = new ArrayList();

        //This is the entire collection.
        Iterator iterator = this.collectionOfCollectionsOfVoPairs.iterator();

        //A LazyList
        List lazyList = null;

        ValueObjectPair voPair = new ValueObjectPair();

        //A container for ValueObjectPair collection.
        VoPairCollectionHolder holder = null;
        while (iterator.hasNext())
            {
            //Gets each collection of ValueObject Pairs.
            Collection voPairCollection = (Collection) iterator.next();

            //Wrap collection containing ValueObjectPairs into a LazyList.
            lazyList =
                LazyCollections.lazyList(new ArrayList(voPairCollection), voPair.getClass());

            //Place each ValueObjectPair collection into a VoPairCollecitonHolder.
            holder = new VoPairCollectionHolder(lazyList);

            //The list now is a collection of VoPairCollection holders.
            list.add(holder);

            //list.add(lazyList);
        }

        //Now Wrap the collection of collections of valueobject pairs in another lazylist
        this.wrappedCollections = LazyCollections.lazyList(list, holder.getClass());

           }
    return this.wrappedCollections;
}



I am about to give up on form auto populate as I am out of time. I will be populating them by hand but anyway... one last attempt. We dont like to lose... do we?



Thanks In Advance

hemant














Re: Wrapping Collections in LazyList to auto-populate form on Submit

Posted by hemant <ya...@softhome.net>.
Arron


Great answer!

Will experiment with my code based on your suggestions and let you know

Thanks for your time

Regards
hemant

----- Original Message -----
From: "Arron Bates" <st...@keyboardmonkey.com>
To: "Struts Users Mailing List" <st...@jakarta.apache.org>
Sent: Wednesday, July 24, 2002 10:46 AM
Subject: Re: Wrapping Collections in LazyList to auto-populate form on
Submit


> The seed beans would be child beans to the banana beans. You'd ask the
> monkey bean for the collection of bananas, and once you have a banana,
> you'd ask the banana for the list of it's seeds. So, the list becomes a
> member of the banana. Looking a little like this...
>
>
> public class BananaBean {
>   public String getFlavour() { return flav; }
>   public void setFlavour(String str) { flav = str; }
>
>   public List getSeeds() { return seedList; }
>
>   private List seedList = LazyCollections.lazyList(new ArrayList(),
>                                                    SeedBean.class);
>   private String flav;
> }
>
>
>
> Nested beans are all about composition. Each nesting level will be
> composed of that beneath it. Monkey's don't manage seeds, they manage
> bananas. Seed management is up to the Banana. If there's another level,
> then the seed bean will take care of that. The Monkey examples of my
> site are an example of all this. What may be confusing is that they
> build objects and at times their children for sake of convenience. But
> the member collections themselves are always attached to the object
> they're concerned with.
>
> So when the request comes in, it will make the monkey object for the
> form. It'll then ask for the banana at the index. When the banana's made
> it will make the lazy wrapped list of seeds. so when an update for a
> seed comes in, then it will make the seed object for the banana.
>
> Once you have one level going, the rest are just as easy. From one to a
> hundred list levels, it's all the same. Other things come to light
> too... you don't have to always have the model start with monkey. Say
> another form which is banana specific, you can use the same banana
> object in another model, and it'll work just as well. Gotta love OOP :)
>
>
> Arron.
>
>
> On Wed, 2002-07-24 at 23:43, hemant wrote:
> > Arron,
> >
> > Thanks for responding.
> >
> > Things seem to be clearer now. I have a question to ask though.
> >
> > We all know Bananas have seeds. (So a BananaBean can have a collection
of
> > seeds.)
> >
> > Now I have a situation where I have to set the property of the seed bean
via
> > the JSP on submit.
> >
> > Lets have a seed bean
> >
> > public class SeedBean {
> >    public String getColor() { return color; }
> >    public void setColor(String str) { color= str; }
> >    private String color;
> >  }
> >
> > Now in the MonkeyBean (Which is the formbean ) can I say the following?
> >
> > public class MonkeyBean {
> >    public List getBananas() { return bananas; }
> >   private List bananas = LazyCollections.lazyList(new
> > ArrayList(LazyCollections.lazyList(new ArrayList(),  SeedBean.class)),
> > BananaBean.class);
> >  }
> >
> >
> > I tried doing the same but it didnt work :(
> >
> > Thanks for your time
> > hemant
> >
> >
> >
> >
> > ----- Original Message -----
> > From: "Arron Bates" <st...@keyboardmonkey.com>
> > To: "Struts Users Mailing List" <st...@jakarta.apache.org>
> > Sent: Tuesday, July 23, 2002 10:19 AM
> > Subject: Re: Wrapping Collections in LazyList to auto-populate form on
> > Submit
> >
> >
> > > Hemant,
> > >
> > > Sorry about the issues you're having, but at face value it seems that
> > > you're almost trying too hard. Without seeing the rest of your code,
> > > it's hard to see what your generateWrappedCollection() method is
trying
> > > to acheive, so I'll try to answer with code...
> > >
> > >
> > > With the collection wrapping, it's a simple one liner in the bean. For
> > > example, in all my monkey examples, they all return the collection as
> > > the indexed property type (because it's a valid indexed getter and the
> > > iterate tags can use the collection to get their thing going). All you
> > > need to do is wrap that collection directly.
> > >
> > >
> > > For example, two complete beans...
> > >
> > > public class MonkeyBean {
> > >   public List getBananas() { return bananas; }
> > >   private List bananas = LazyCollections.lazyList(new ArrayList(),
> > >                                                   BananaBean.class);
> > > }
> > >
> > > public class BananaBean {
> > >   public String getFlavour() { return flav; }
> > >   public void setFlavour(String str) { flav = str; }
> > >   private String flav;
> > > }
> > >
> > >
> > >
> > > The MonkeyBean is the parent class that hold the collection. It has
> > > immediately wrapped the ArrayList in the LazyCollection, and passed it
> > > the class of the BananaBean object. You may want to keep a reference
to
> > > the wrapped ArrayList, generally I don't have the need to.
> > >
> > > These classes are all but ready to rock. In the action class, query
the
> > > database or whatever and populate the MonkeyBean with the BananaBean
> > > data. Serve the result to the JSP.
> > >
> > > JSP write out a list of text boxes using iterate tags. Submit this,
and
> > > after the monkeybean is built, the lazy collection will grow the
banana
> > > list with banana beans as the indexed requests come in.
> > >
> > > When it gets back to your action class, you'll have your collection of
> > > banana beans.
> > >
> > > Hope this helps, you know where we are if it doesn't.
> > >
> > >
> > > Arron.
> > >
> > >
> > >
> > > On Mon, 2002-07-22 at 22:59, hemant wrote:
> > > > Comrades,
> > > >
> > > >
> > > > Objective: To autopopulate forms on submit. The formbean "has a"
> > collection of collections of ValueObjects. Each valueObject contains a
pair
> > of other Value Objects.
> > > >
> > > > Before people beat me up,  The following possibilities have been
dealt
> > with:
> > > >
> > > > 1>> No, this is not a case of reset() I have the collections
initialized
> > and things are fine.
> > > >
> > > > 2>> It is not a case of bean being in request scope. By default the
bean
> > is in session scope (Unless we explicitly mention the action attribute
that
> > it is request scope.)
> > >
> > > [ ...cut...]
> > >
> > > >
> > > > I am about to give up on form auto populate as I am out of time. I
will
> > be populating them by hand but anyway... one last attempt. We dont like
to
> > lose... do we?
> > > >
> > > >
> > > >
> > > > Thanks In Advance
> > > >
> > > > hemant
> > >
> > >
> > > --
> > > 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>
>
>
>
> --
> 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: Wrapping Collections in LazyList to auto-populate form on Submit

Posted by hemant <ya...@softhome.net>.
Arron,

Upon reading your reply, i modified my MonkeyBean and BananaBean  to have a
wrapped BananaBean List and  wrapped SeedBean List respectively.

I fire up the page and submit, and check for the changes in the BananaBean
List in MonkeyBean  but the change in seed information does not seem to be
updated in the banana list upon submit.

Any bonehead thing that I might have done?

"> So when the request comes in, it will make the monkey object for the
> form. It'll then ask for the banana at the index. When the banana's made
> it will make the lazy wrapped list of seeds. so when an update for a
> seed comes in, then it will make the seed object for the banana.
"

So is it possible that the new Banana and new Seed are not being created at
all? and as a result the seed/banana data is not being set?


Regards
hemant




----- Original Message -----
From: "Arron Bates" <st...@keyboardmonkey.com>
To: "Struts Users Mailing List" <st...@jakarta.apache.org>
Sent: Wednesday, July 24, 2002 10:46 AM
Subject: Re: Wrapping Collections in LazyList to auto-populate form on
Submit


> The seed beans would be child beans to the banana beans. You'd ask the
> monkey bean for the collection of bananas, and once you have a banana,
> you'd ask the banana for the list of it's seeds. So, the list becomes a
> member of the banana. Looking a little like this...
>
>
> public class BananaBean {
>   public String getFlavour() { return flav; }
>   public void setFlavour(String str) { flav = str; }
>
>   public List getSeeds() { return seedList; }
>
>   private List seedList = LazyCollections.lazyList(new ArrayList(),
>                                                    SeedBean.class);
>   private String flav;
> }
>
>
>
> Nested beans are all about composition. Each nesting level will be
> composed of that beneath it. Monkey's don't manage seeds, they manage
> bananas. Seed management is up to the Banana. If there's another level,
> then the seed bean will take care of that. The Monkey examples of my
> site are an example of all this. What may be confusing is that they
> build objects and at times their children for sake of convenience. But
> the member collections themselves are always attached to the object
> they're concerned with.
>
> So when the request comes in, it will make the monkey object for the
> form. It'll then ask for the banana at the index. When the banana's made
> it will make the lazy wrapped list of seeds. so when an update for a
> seed comes in, then it will make the seed object for the banana.
>
> Once you have one level going, the rest are just as easy. From one to a
> hundred list levels, it's all the same. Other things come to light
> too... you don't have to always have the model start with monkey. Say
> another form which is banana specific, you can use the same banana
> object in another model, and it'll work just as well. Gotta love OOP :)
>
>
> Arron.
>
>
> On Wed, 2002-07-24 at 23:43, hemant wrote:
> > Arron,
> >
> > Thanks for responding.
> >
> > Things seem to be clearer now. I have a question to ask though.
> >
> > We all know Bananas have seeds. (So a BananaBean can have a collection
of
> > seeds.)
> >
> > Now I have a situation where I have to set the property of the seed bean
via
> > the JSP on submit.
> >
> > Lets have a seed bean
> >
> > public class SeedBean {
> >    public String getColor() { return color; }
> >    public void setColor(String str) { color= str; }
> >    private String color;
> >  }
> >
> > Now in the MonkeyBean (Which is the formbean ) can I say the following?
> >
> > public class MonkeyBean {
> >    public List getBananas() { return bananas; }
> >   private List bananas = LazyCollections.lazyList(new
> > ArrayList(LazyCollections.lazyList(new ArrayList(),  SeedBean.class)),
> > BananaBean.class);
> >  }
> >
> >
> > I tried doing the same but it didnt work :(
> >
> > Thanks for your time
> > hemant
> >
> >
> >
> >
> > ----- Original Message -----
> > From: "Arron Bates" <st...@keyboardmonkey.com>
> > To: "Struts Users Mailing List" <st...@jakarta.apache.org>
> > Sent: Tuesday, July 23, 2002 10:19 AM
> > Subject: Re: Wrapping Collections in LazyList to auto-populate form on
> > Submit
> >
> >
> > > Hemant,
> > >
> > > Sorry about the issues you're having, but at face value it seems that
> > > you're almost trying too hard. Without seeing the rest of your code,
> > > it's hard to see what your generateWrappedCollection() method is
trying
> > > to acheive, so I'll try to answer with code...
> > >
> > >
> > > With the collection wrapping, it's a simple one liner in the bean. For
> > > example, in all my monkey examples, they all return the collection as
> > > the indexed property type (because it's a valid indexed getter and the
> > > iterate tags can use the collection to get their thing going). All you
> > > need to do is wrap that collection directly.
> > >
> > >
> > > For example, two complete beans...
> > >
> > > public class MonkeyBean {
> > >   public List getBananas() { return bananas; }
> > >   private List bananas = LazyCollections.lazyList(new ArrayList(),
> > >                                                   BananaBean.class);
> > > }
> > >
> > > public class BananaBean {
> > >   public String getFlavour() { return flav; }
> > >   public void setFlavour(String str) { flav = str; }
> > >   private String flav;
> > > }
> > >
> > >
> > >
> > > The MonkeyBean is the parent class that hold the collection. It has
> > > immediately wrapped the ArrayList in the LazyCollection, and passed it
> > > the class of the BananaBean object. You may want to keep a reference
to
> > > the wrapped ArrayList, generally I don't have the need to.
> > >
> > > These classes are all but ready to rock. In the action class, query
the
> > > database or whatever and populate the MonkeyBean with the BananaBean
> > > data. Serve the result to the JSP.
> > >
> > > JSP write out a list of text boxes using iterate tags. Submit this,
and
> > > after the monkeybean is built, the lazy collection will grow the
banana
> > > list with banana beans as the indexed requests come in.
> > >
> > > When it gets back to your action class, you'll have your collection of
> > > banana beans.
> > >
> > > Hope this helps, you know where we are if it doesn't.
> > >
> > >
> > > Arron.
> > >
> > >
> > >
> > > On Mon, 2002-07-22 at 22:59, hemant wrote:
> > > > Comrades,
> > > >
> > > >
> > > > Objective: To autopopulate forms on submit. The formbean "has a"
> > collection of collections of ValueObjects. Each valueObject contains a
pair
> > of other Value Objects.
> > > >
> > > > Before people beat me up,  The following possibilities have been
dealt
> > with:
> > > >
> > > > 1>> No, this is not a case of reset() I have the collections
initialized
> > and things are fine.
> > > >
> > > > 2>> It is not a case of bean being in request scope. By default the
bean
> > is in session scope (Unless we explicitly mention the action attribute
that
> > it is request scope.)
> > >
> > > [ ...cut...]
> > >
> > > >
> > > > I am about to give up on form auto populate as I am out of time. I
will
> > be populating them by hand but anyway... one last attempt. We dont like
to
> > lose... do we?
> > > >
> > > >
> > > >
> > > > Thanks In Advance
> > > >
> > > > hemant
> > >
> > >
> > > --
> > > 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>
>
>
>
> --
> 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: Wrapping Collections in LazyList to auto-populate form on Submit

Posted by Arron Bates <st...@keyboardmonkey.com>.
The seed beans would be child beans to the banana beans. You'd ask the
monkey bean for the collection of bananas, and once you have a banana,
you'd ask the banana for the list of it's seeds. So, the list becomes a
member of the banana. Looking a little like this...


public class BananaBean {
  public String getFlavour() { return flav; }
  public void setFlavour(String str) { flav = str; }

  public List getSeeds() { return seedList; }

  private List seedList = LazyCollections.lazyList(new ArrayList(),
                                                   SeedBean.class);
  private String flav;
}



Nested beans are all about composition. Each nesting level will be
composed of that beneath it. Monkey's don't manage seeds, they manage
bananas. Seed management is up to the Banana. If there's another level,
then the seed bean will take care of that. The Monkey examples of my
site are an example of all this. What may be confusing is that they
build objects and at times their children for sake of convenience. But
the member collections themselves are always attached to the object
they're concerned with.

So when the request comes in, it will make the monkey object for the
form. It'll then ask for the banana at the index. When the banana's made
it will make the lazy wrapped list of seeds. so when an update for a
seed comes in, then it will make the seed object for the banana. 

Once you have one level going, the rest are just as easy. From one to a
hundred list levels, it's all the same. Other things come to light
too... you don't have to always have the model start with monkey. Say
another form which is banana specific, you can use the same banana
object in another model, and it'll work just as well. Gotta love OOP :)


Arron.


On Wed, 2002-07-24 at 23:43, hemant wrote:
> Arron,
> 
> Thanks for responding.
> 
> Things seem to be clearer now. I have a question to ask though.
> 
> We all know Bananas have seeds. (So a BananaBean can have a collection of
> seeds.)
> 
> Now I have a situation where I have to set the property of the seed bean via
> the JSP on submit.
> 
> Lets have a seed bean
> 
> public class SeedBean {
>    public String getColor() { return color; }
>    public void setColor(String str) { color= str; }
>    private String color;
>  }
> 
> Now in the MonkeyBean (Which is the formbean ) can I say the following?
> 
> public class MonkeyBean {
>    public List getBananas() { return bananas; }
>   private List bananas = LazyCollections.lazyList(new
> ArrayList(LazyCollections.lazyList(new ArrayList(),  SeedBean.class)),
> BananaBean.class);
>  }
> 
> 
> I tried doing the same but it didnt work :(
> 
> Thanks for your time
> hemant
> 
> 
> 
> 
> ----- Original Message -----
> From: "Arron Bates" <st...@keyboardmonkey.com>
> To: "Struts Users Mailing List" <st...@jakarta.apache.org>
> Sent: Tuesday, July 23, 2002 10:19 AM
> Subject: Re: Wrapping Collections in LazyList to auto-populate form on
> Submit
> 
> 
> > Hemant,
> >
> > Sorry about the issues you're having, but at face value it seems that
> > you're almost trying too hard. Without seeing the rest of your code,
> > it's hard to see what your generateWrappedCollection() method is trying
> > to acheive, so I'll try to answer with code...
> >
> >
> > With the collection wrapping, it's a simple one liner in the bean. For
> > example, in all my monkey examples, they all return the collection as
> > the indexed property type (because it's a valid indexed getter and the
> > iterate tags can use the collection to get their thing going). All you
> > need to do is wrap that collection directly.
> >
> >
> > For example, two complete beans...
> >
> > public class MonkeyBean {
> >   public List getBananas() { return bananas; }
> >   private List bananas = LazyCollections.lazyList(new ArrayList(),
> >                                                   BananaBean.class);
> > }
> >
> > public class BananaBean {
> >   public String getFlavour() { return flav; }
> >   public void setFlavour(String str) { flav = str; }
> >   private String flav;
> > }
> >
> >
> >
> > The MonkeyBean is the parent class that hold the collection. It has
> > immediately wrapped the ArrayList in the LazyCollection, and passed it
> > the class of the BananaBean object. You may want to keep a reference to
> > the wrapped ArrayList, generally I don't have the need to.
> >
> > These classes are all but ready to rock. In the action class, query the
> > database or whatever and populate the MonkeyBean with the BananaBean
> > data. Serve the result to the JSP.
> >
> > JSP write out a list of text boxes using iterate tags. Submit this, and
> > after the monkeybean is built, the lazy collection will grow the banana
> > list with banana beans as the indexed requests come in.
> >
> > When it gets back to your action class, you'll have your collection of
> > banana beans.
> >
> > Hope this helps, you know where we are if it doesn't.
> >
> >
> > Arron.
> >
> >
> >
> > On Mon, 2002-07-22 at 22:59, hemant wrote:
> > > Comrades,
> > >
> > >
> > > Objective: To autopopulate forms on submit. The formbean "has a"
> collection of collections of ValueObjects. Each valueObject contains a pair
> of other Value Objects.
> > >
> > > Before people beat me up,  The following possibilities have been dealt
> with:
> > >
> > > 1>> No, this is not a case of reset() I have the collections initialized
> and things are fine.
> > >
> > > 2>> It is not a case of bean being in request scope. By default the bean
> is in session scope (Unless we explicitly mention the action attribute that
> it is request scope.)
> >
> > [ ...cut...]
> >
> > >
> > > I am about to give up on form auto populate as I am out of time. I will
> be populating them by hand but anyway... one last attempt. We dont like to
> lose... do we?
> > >
> > >
> > >
> > > Thanks In Advance
> > >
> > > hemant
> >
> >
> > --
> > 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>



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


Re: Wrapping Collections in LazyList to auto-populate form on Submit

Posted by hemant <ya...@softhome.net>.
Arron,

Thanks for responding.

Things seem to be clearer now. I have a question to ask though.

We all know Bananas have seeds. (So a BananaBean can have a collection of
seeds.)

Now I have a situation where I have to set the property of the seed bean via
the JSP on submit.

Lets have a seed bean

public class SeedBean {
   public String getColor() { return color; }
   public void setColor(String str) { color= str; }
   private String color;
 }

Now in the MonkeyBean (Which is the formbean ) can I say the following?

public class MonkeyBean {
   public List getBananas() { return bananas; }
  private List bananas = LazyCollections.lazyList(new
ArrayList(LazyCollections.lazyList(new ArrayList(),  SeedBean.class)),
BananaBean.class);
 }


I tried doing the same but it didnt work :(

Thanks for your time
hemant




----- Original Message -----
From: "Arron Bates" <st...@keyboardmonkey.com>
To: "Struts Users Mailing List" <st...@jakarta.apache.org>
Sent: Tuesday, July 23, 2002 10:19 AM
Subject: Re: Wrapping Collections in LazyList to auto-populate form on
Submit


> Hemant,
>
> Sorry about the issues you're having, but at face value it seems that
> you're almost trying too hard. Without seeing the rest of your code,
> it's hard to see what your generateWrappedCollection() method is trying
> to acheive, so I'll try to answer with code...
>
>
> With the collection wrapping, it's a simple one liner in the bean. For
> example, in all my monkey examples, they all return the collection as
> the indexed property type (because it's a valid indexed getter and the
> iterate tags can use the collection to get their thing going). All you
> need to do is wrap that collection directly.
>
>
> For example, two complete beans...
>
> public class MonkeyBean {
>   public List getBananas() { return bananas; }
>   private List bananas = LazyCollections.lazyList(new ArrayList(),
>                                                   BananaBean.class);
> }
>
> public class BananaBean {
>   public String getFlavour() { return flav; }
>   public void setFlavour(String str) { flav = str; }
>   private String flav;
> }
>
>
>
> The MonkeyBean is the parent class that hold the collection. It has
> immediately wrapped the ArrayList in the LazyCollection, and passed it
> the class of the BananaBean object. You may want to keep a reference to
> the wrapped ArrayList, generally I don't have the need to.
>
> These classes are all but ready to rock. In the action class, query the
> database or whatever and populate the MonkeyBean with the BananaBean
> data. Serve the result to the JSP.
>
> JSP write out a list of text boxes using iterate tags. Submit this, and
> after the monkeybean is built, the lazy collection will grow the banana
> list with banana beans as the indexed requests come in.
>
> When it gets back to your action class, you'll have your collection of
> banana beans.
>
> Hope this helps, you know where we are if it doesn't.
>
>
> Arron.
>
>
>
> On Mon, 2002-07-22 at 22:59, hemant wrote:
> > Comrades,
> >
> >
> > Objective: To autopopulate forms on submit. The formbean "has a"
collection of collections of ValueObjects. Each valueObject contains a pair
of other Value Objects.
> >
> > Before people beat me up,  The following possibilities have been dealt
with:
> >
> > 1>> No, this is not a case of reset() I have the collections initialized
and things are fine.
> >
> > 2>> It is not a case of bean being in request scope. By default the bean
is in session scope (Unless we explicitly mention the action attribute that
it is request scope.)
>
> [ ...cut...]
>
> >
> > I am about to give up on form auto populate as I am out of time. I will
be populating them by hand but anyway... one last attempt. We dont like to
lose... do we?
> >
> >
> >
> > Thanks In Advance
> >
> > hemant
>
>
> --
> 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: Wrapping Collections in LazyList to auto-populate form on Submit

Posted by Arron Bates <st...@keyboardmonkey.com>.
Hemant,

Sorry about the issues you're having, but at face value it seems that
you're almost trying too hard. Without seeing the rest of your code,
it's hard to see what your generateWrappedCollection() method is trying
to acheive, so I'll try to answer with code...


With the collection wrapping, it's a simple one liner in the bean. For
example, in all my monkey examples, they all return the collection as
the indexed property type (because it's a valid indexed getter and the
iterate tags can use the collection to get their thing going). All you
need to do is wrap that collection directly.


For example, two complete beans...

public class MonkeyBean {
  public List getBananas() { return bananas; }
  private List bananas = LazyCollections.lazyList(new ArrayList(),
                                                  BananaBean.class);
}

public class BananaBean {
  public String getFlavour() { return flav; }
  public void setFlavour(String str) { flav = str; }
  private String flav;
}



The MonkeyBean is the parent class that hold the collection. It has
immediately wrapped the ArrayList in the LazyCollection, and passed it
the class of the BananaBean object. You may want to keep a reference to
the wrapped ArrayList, generally I don't have the need to.

These classes are all but ready to rock. In the action class, query the
database or whatever and populate the MonkeyBean with the BananaBean
data. Serve the result to the JSP.

JSP write out a list of text boxes using iterate tags. Submit this, and
after the monkeybean is built, the lazy collection will grow the banana
list with banana beans as the indexed requests come in.

When it gets back to your action class, you'll have your collection of
banana beans.

Hope this helps, you know where we are if it doesn't.


Arron.



On Mon, 2002-07-22 at 22:59, hemant wrote:
> Comrades,
>
> 
> Objective: To autopopulate forms on submit. The formbean "has a" collection of collections of ValueObjects. Each valueObject contains a pair of other Value Objects.
> 
> Before people beat me up,  The following possibilities have been dealt with:
> 
> 1>> No, this is not a case of reset() I have the collections initialized and things are fine. 
> 
> 2>> It is not a case of bean being in request scope. By default the bean is in session scope (Unless we explicitly mention the action attribute that it is request scope.)

[ ...cut...]

> 
> I am about to give up on form auto populate as I am out of time. I will be populating them by hand but anyway... one last attempt. We dont like to lose... do we?
> 
> 
> 
> Thanks In Advance
> 
> hemant


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