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

2002-07-24 Thread hemant

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 [EMAIL PROTECTED]
To: Struts Users Mailing List [EMAIL PROTECTED]
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:
mailto:[EMAIL PROTECTED]
 For additional commands, e-mail:
mailto:[EMAIL PROTECTED]



--
To unsubscribe, e-mail:   mailto:[EMAIL PROTECTED]
For additional commands, e-mail: mailto:[EMAIL PROTECTED]




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

2002-07-24 Thread Arron Bates

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 [EMAIL PROTECTED]
 To: Struts Users Mailing List [EMAIL PROTECTED]
 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 

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

2002-07-24 Thread hemant

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 [EMAIL PROTECTED]
To: Struts Users Mailing List [EMAIL PROTECTED]
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 [EMAIL PROTECTED]
  To: Struts Users Mailing List [EMAIL PROTECTED]
  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 

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

2002-07-24 Thread Jeff_Mychasiw


Two questions:
  1 - In our situation we will be getting a *result* object with an
internal list from the backend that is similar to the MonkeyBean.
  I would NOT be able to change it's implementation (ie:adding
LazyCollections) .  How could I achieve the same thing?  Would I need to
create to temporary list wrappers that would be used to  manually insert
the newly created lists ?

  2 - Are the LazyCollections public now. The last I heard they were on
there way to Commons. I have been checking Arrons site and have seen to
mention
of them.  I also understand that some of the tutorials will be updated with
the lazy collections instead of putting the list in session.  Is this the
case?

Thanks




hemant [EMAIL PROTECTED] on 07/24/2002 10:02:05 AM

Please respond to Struts Users Mailing List
   [EMAIL PROTECTED]

To:Struts Users Mailing List [EMAIL PROTECTED]
cc:

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


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 [EMAIL PROTECTED]
To: Struts Users Mailing List [EMAIL PROTECTED]
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 [EMAIL PROTECTED]
  To: Struts Users Mailing List [EMAIL PROTECTED]
  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 

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

2002-07-24 Thread hemant

To answer your second question, the LazyCollections aren't yet public
(unless I am in some kinda coma) , they can be found in commons nightly
builds.This is  OO Software Craftsmanship at its best!! The code is very
well documented and should be enough to get you going.

regards
hemant



- Original Message -
From: [EMAIL PROTECTED]
To: Struts Users Mailing List [EMAIL PROTECTED]
Sent: Wednesday, July 24, 2002 11:22 AM
Subject: Re: Wrapping Collections in LazyList to auto-populate form on
Submit



 Two questions:
   1 - In our situation we will be getting a *result* object with an
 internal list from the backend that is similar to the MonkeyBean.
   I would NOT be able to change it's implementation (ie:adding
 LazyCollections) .  How could I achieve the same thing?  Would I need to
 create to temporary list wrappers that would be used to  manually insert
 the newly created lists ?

   2 - Are the LazyCollections public now. The last I heard they were
on
 there way to Commons. I have been checking Arrons site and have seen to
 mention
 of them.  I also understand that some of the tutorials will be updated
with
 the lazy collections instead of putting the list in session.  Is this the
 case?

 Thanks




 hemant [EMAIL PROTECTED] on 07/24/2002 10:02:05 AM

 Please respond to Struts Users Mailing List
[EMAIL PROTECTED]

 To:Struts Users Mailing List [EMAIL PROTECTED]
 cc:

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


 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 [EMAIL PROTECTED]
 To: Struts Users Mailing List [EMAIL PROTECTED]
 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 [EMAIL PROTECTED]
   To: Struts Users Mailing List [EMAIL PROTECTED]
   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 

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

2002-07-24 Thread hemant

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 [EMAIL PROTECTED]
To: Struts Users Mailing List [EMAIL PROTECTED]
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 [EMAIL PROTECTED]
  To: Struts Users Mailing List [EMAIL PROTECTED]
  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; 

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

2002-07-23 Thread Arron Bates

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:   mailto:[EMAIL PROTECTED]
For additional commands, e-mail: mailto:[EMAIL PROTECTED]




Wrapping Collections in LazyList to auto-populate form on Submit

2002-07-22 Thread hemant

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