You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by Rick Reumann <st...@reumann.net> on 2005/12/28 23:52:04 UTC

Revisiting nested Lists (again:) using Request scope ( also related to LazyList )

I'm still stumped with the best way to handle cases where your nesting 
goes a bit deeper than just into one list in your ActionForm (and you 
want to use Request scope for your ActionForm). Yes, I know many of you 
state that it means you have a complicated UI, but I've had numerous 
questions come to me personally about master-detail forms where you do 
edit several records from a single form, so I'm going to write up a 
tutorial on it.

For example lets assume you want to edit on a single JSP a list of 
Employees - where you want to be able to edit their "name" AND "phone 
numbers":

(imagine data below in editable text fields)

Employee              Phone Numbers
--------              -------------
John Doe              888-888-8888
                       888-111-1111
                       222-222-2222

Bill Boo              111-111-3333
                       444-333-3333

          [Submit Button]


So we might have a List of Employee objects where Employee has:
    String name;
    List phoneNumbers;

And our ActionForm bean thus has a single property:
    List employees;

Here's the problem.... in the reset method you can set a LazyList to 
wrap the Employees but there is still the problem of the internal List 
of phoneNumbers in each Employee.

I was trying:

  public void reset(ActionMapping actionMapping, HttpServletRequest 
httpServletRequest) {

     employees = ListUtils.lazyList(new java.util.ArrayList(), new 
Factory() {
         public Object create() {
             return buildEmployee();
         }
     });
  }

private Employee buildEmployee() {
    //This really isn't working,
    //I'll still get  an index out of bounds, when
    //trying to set an index of the phoneNumbers list
     Employee emp = new Employee();
     List phoneNumbers = ListUtils.lazyList(new java.util.ArrayList(), 
new Factory() {
         public Object create() {
             return new String();
         }
     });
     emp.setPhoneNumbers( phoneNumbers );
     return emp;

}


Of course all of these problems go away if I just use the Session to 
store the form (which at this point, I'm about to say that simply is THE 
BEST PRACTICE for this kind of stuff), but I really want to figure out 
if there is a semi-nice way to get this to work using the Request.

I've looked at:
http://www.niallp.pwp.blueyonder.co.uk/lazyactionform.html
http://wiki.apache.org/struts/StrutsCatalogLazyList

But I'm still a bit stumped here on how to best implement this since 
most of those example seem to only deal with nesting one List deep.

-- 
Rick

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


Re: Revisiting nested Lists (again:) using Request scope ( also related to LazyList )

Posted by Rick R <st...@reumann.net>.
Frank W. Zammetti wrote:
> Rick, what is the real problem here?  I ask because what your trying to 
> do seems reasonable to me and I'd probably do something similar, 
> although I probably wouldn't use LazyList (I'd probably build the list 
> manually), but that doesn't really matter.  I would *not* use session 
> for this as I can't think of a single good reason to do so (well, aside 
> from maing it WORK of course!).

The problem is Frank when you don't use the Session you will get index 
out of bounds errors when the form tries to submit since the first thing 
done is reset all the form values before BeanUtils tries to populate 
them - so that when the form tries to populate the List items you'll get 
indexOutOfBounds errors. So for just a one deep List in your ActionForm 
it's not too big a of deal since a LazyList will work. (I'm curious how 
would you accomplish this WITHOU using a LazyList or using the Session? 
- the only other option is in the reset method you make sure you 
initialize your list add enough items to your List so that when the form 
submits it will cover all your possible values - way annoying since you 
need to know the size of the list in the reset method which is a pain - 
hence the LazyList is just awesome). I'm running into trying to figure 
out the best scenario for populating at least one more level deep. In 
other words the source code might look like...

<html type="text" name="foo[3].bar[2].someProperty" value="something"/>

(In my simple case I'm just working with employees[2].phoneNumbers[1] etc)

JSF handles this stuff nicely (although I'm not sure of the mechanics of 
how it's accomplished, but it works:).



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


Re: Revisiting nested Lists (again:) using Request scope ( also related to LazyList )

Posted by "Frank W. Zammetti" <fz...@omnytex.com>.
Rick, what is the real problem here?  I ask because what your trying to 
do seems reasonable to me and I'd probably do something similar, 
although I probably wouldn't use LazyList (I'd probably build the list 
manually), but that doesn't really matter.  I would *not* use session 
for this as I can't think of a single good reason to do so (well, aside 
from maing it WORK of course!).

I noticed your comments about the phone numbers part still not working. 
  Is *that* the problem your really trying to solve?

I personally think people are too quick to use session for too many 
things these days, and many times (arguably at least) inappropriate 
things.  Until someone can convince to me that it doesn't have 
performance impacts in a distributed environment (and if you aren't 
building your apps to be distributed-friendly your setting yourself up 
for trouble later), I still favor request scope whenever possible.  At 
least, I wouldn't want to see it stated as a best practice as I still 
think the best practice is to avoid session whenever possible (sometimes 
it isn't possible of course).

Frank

Rick Reumann wrote:
> I'm still stumped with the best way to handle cases where your nesting 
> goes a bit deeper than just into one list in your ActionForm (and you 
> want to use Request scope for your ActionForm). Yes, I know many of you 
> state that it means you have a complicated UI, but I've had numerous 
> questions come to me personally about master-detail forms where you do 
> edit several records from a single form, so I'm going to write up a 
> tutorial on it.
> 
> For example lets assume you want to edit on a single JSP a list of 
> Employees - where you want to be able to edit their "name" AND "phone 
> numbers":
> 
> (imagine data below in editable text fields)
> 
> Employee              Phone Numbers
> --------              -------------
> John Doe              888-888-8888
>                       888-111-1111
>                       222-222-2222
> 
> Bill Boo              111-111-3333
>                       444-333-3333
> 
>          [Submit Button]
> 
> 
> So we might have a List of Employee objects where Employee has:
>    String name;
>    List phoneNumbers;
> 
> And our ActionForm bean thus has a single property:
>    List employees;
> 
> Here's the problem.... in the reset method you can set a LazyList to 
> wrap the Employees but there is still the problem of the internal List 
> of phoneNumbers in each Employee.
> 
> I was trying:
> 
>  public void reset(ActionMapping actionMapping, HttpServletRequest 
> httpServletRequest) {
> 
>     employees = ListUtils.lazyList(new java.util.ArrayList(), new 
> Factory() {
>         public Object create() {
>             return buildEmployee();
>         }
>     });
>  }
> 
> private Employee buildEmployee() {
>    //This really isn't working,
>    //I'll still get  an index out of bounds, when
>    //trying to set an index of the phoneNumbers list
>     Employee emp = new Employee();
>     List phoneNumbers = ListUtils.lazyList(new java.util.ArrayList(), 
> new Factory() {
>         public Object create() {
>             return new String();
>         }
>     });
>     emp.setPhoneNumbers( phoneNumbers );
>     return emp;
> 
> }
> 
> 
> Of course all of these problems go away if I just use the Session to 
> store the form (which at this point, I'm about to say that simply is THE 
> BEST PRACTICE for this kind of stuff), but I really want to figure out 
> if there is a semi-nice way to get this to work using the Request.
> 
> I've looked at:
> http://www.niallp.pwp.blueyonder.co.uk/lazyactionform.html
> http://wiki.apache.org/struts/StrutsCatalogLazyList
> 
> But I'm still a bit stumped here on how to best implement this since 
> most of those example seem to only deal with nesting one List deep.
> 

-- 
Frank W. Zammetti
Founder and Chief Software Architect
Omnytex Technologies
http://www.omnytex.com
AIM: fzammetti
Yahoo: fzammetti
MSN: fzammetti@hotmail.com

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


Re: [solved] Revisiting nested Lists (again:) using Request scope ( also related to LazyList )

Posted by Priya Saloni <sa...@gmail.com>.
Hi Rick,

Iam getting problem while iam trying to use the following code in my JSP

   <nested:iterate property="skills">
       <nested:text property="skillId"/>
   </nested:iterate>

I got that code from the article

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

Priya


On 12/29/05, Rick R <st...@reumann.net> wrote:
>
> Frank W. Zammetti wrote:
> >
> > I'm still though thinking about your question regarding how I would do
> > it... I've never used LazyList, although I can see why you did.  Using
> the
> > reset() method in this way has been nagging me though because I
> typically
> > would never use it except when dealing with checkboxes... something is
> > bugging me about it and I'm not entirely sure what it is at this point,
> > just kind of a gut feeling with nothing to back it up :)
>
> Try it without using a LazyList and you'll see the headaches:) I think
> you'll soon see there is no clean way to do it without one (at least
> none that I'm aware of). Either way, you will have to 'something' in the
> reset method for Lists (assuming you want to be a good camper and use
> request scoped ActionForms:)
>
> --
> Rick
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
> For additional commands, e-mail: user-help@struts.apache.org
>
>

Re: [solved] Revisiting nested Lists (again:) using Request scope ( also related to LazyList )

Posted by Priya Saloni <sa...@gmail.com>.
Thanks Geeta,

I have  Commons-Collections 2.1.1.Now no problem.


On 12/29/05, gramani@intellicare.com <gr...@intellicare.com> wrote:
>
> Priya Saloni <sa...@gmail.com> wrote on 12/29/2005 02:50:06 PM:
>
> > Sorry for the dumb question but i have to ask ..from where i can get
> this
> > class org.apache.commons.collections.list.LazyList..
> >
> > from this url
> > http://jakarta.apache.org/commons/collections/apidocs-
> > COLLECTIONS_3_1/org/apache/commons/collections/list/LazyList.html
> >
> > I found out that its part of Commons Collections 3.0 ,but how can i add
> it
> > to my class path? from where i need to download it?
>
> Download from here:
> http://jakarta.apache.org/commons/collections/
>
> >
> > Iam getting the Beanutils problem when iam working in request scope and
> it
> > works fine in session scope.
> >
> > Thanks In Advance
> >
> > Priya
> >
>
> Geeta
>
>
>

Re: [solved] Revisiting nested Lists (again:) using Request scope ( also related to LazyList )

Posted by gr...@intellicare.com.
Priya Saloni <sa...@gmail.com> wrote on 12/29/2005 02:50:06 PM:

> Sorry for the dumb question but i have to ask ..from where i can get 
this
> class org.apache.commons.collections.list.LazyList..
> 
> from this url
> http://jakarta.apache.org/commons/collections/apidocs-
> COLLECTIONS_3_1/org/apache/commons/collections/list/LazyList.html
> 
> I found out that its part of Commons Collections 3.0 ,but how can i add 
it
> to my class path? from where i need to download it?

Download from here:
http://jakarta.apache.org/commons/collections/

> 
> Iam getting the Beanutils problem when iam working in request scope and 
it
> works fine in session scope.
> 
> Thanks In Advance
> 
> Priya
> 

Geeta


Re: [solved] Revisiting nested Lists (again:) using Request scope ( also related to LazyList )

Posted by Priya Saloni <sa...@gmail.com>.
Sorry for the dumb question but i have to ask ..from where i can get this
class org.apache.commons.collections.list.LazyList..

from this url
http://jakarta.apache.org/commons/collections/apidocs-COLLECTIONS_3_1/org/apache/commons/collections/list/LazyList.html

I found out that its part of Commons Collections 3.0 ,but how can i add it
to my class path? from where i need to download it?

Iam getting the Beanutils problem when iam working in request scope and it
works fine in session scope.

Thanks In Advance

Priya

On 12/29/05, Rick R <st...@reumann.net> wrote:
>
> Frank W. Zammetti wrote:
> >
> > I'm still though thinking about your question regarding how I would do
> > it... I've never used LazyList, although I can see why you did.  Using
> the
> > reset() method in this way has been nagging me though because I
> typically
> > would never use it except when dealing with checkboxes... something is
> > bugging me about it and I'm not entirely sure what it is at this point,
> > just kind of a gut feeling with nothing to back it up :)
>
> Try it without using a LazyList and you'll see the headaches:) I think
> you'll soon see there is no clean way to do it without one (at least
> none that I'm aware of). Either way, you will have to 'something' in the
> reset method for Lists (assuming you want to be a good camper and use
> request scoped ActionForms:)
>
> --
> Rick
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
> For additional commands, e-mail: user-help@struts.apache.org
>
>

Re: [solved] Revisiting nested Lists (again:) using Request scope ( also related to LazyList )

Posted by Rick R <st...@reumann.net>.
Frank W. Zammetti wrote:
>  
> I'm still though thinking about your question regarding how I would do
> it... I've never used LazyList, although I can see why you did.  Using the
> reset() method in this way has been nagging me though because I typically
> would never use it except when dealing with checkboxes... something is
> bugging me about it and I'm not entirely sure what it is at this point,
> just kind of a gut feeling with nothing to back it up :)  

Try it without using a LazyList and you'll see the headaches:) I think 
you'll soon see there is no clean way to do it without one (at least 
none that I'm aware of). Either way, you will have to 'something' in the 
reset method for Lists (assuming you want to be a good camper and use 
request scoped ActionForms:)

-- 
Rick


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


Re: [solved] Revisiting nested Lists (again:) using Request scope ( also related to LazyList )

Posted by "Frank W. Zammetti" <fz...@omnytex.com>.
Good catch indeed Tamas!  I was just getting around to replying to you
Rick, after some PC problems last night stopped me from doing so sooner,
and I was coming to the exact same conclusion when I saw Tamas' reply.  He
beat me to the punch :)

I'm still though thinking about your question regarding how I would do
it... I've never used LazyList, although I can see why you did.  Using the
reset() method in this way has been nagging me though because I typically
would never use it except when dealing with checkboxes... something is
bugging me about it and I'm not entirely sure what it is at this point,
just kind of a gut feeling with nothing to back it up :)  I was more
concerned with trying to figure out why what you had wouldn't work because
I found it interesting, but I'm not sure how I would respond to your
question about what I would do instead... I'll have to think about it a
bit :)

-- 
Frank W. Zammetti
Founder and Chief Software Architect
Omnytex Technologies
http://www.omnytex.com
AIM: fzammetti
Yahoo: fzammetti
MSN: fzammetti@hotmail.com

On Thu, December 29, 2005 12:36 pm, Rick R said:
> Tamas Szabo wrote:
>
>> You will have to use a PhoneNumber object so you will have a reference
>> to
>> employee[idx1].phoneNumbers[idx2].number in your html:text.
>
> Thanks Tamas!  That was exactly the problem. Typically I do exactly that
> and use lists of beans, but this time I thought I'd make the demo more
> simple by just having a List of Strings, but ironically that made it
> more difficult. I just built a Contact object instead to hold
> phoneNumber and now all is well.
>
> Thanks again!
>
> --
> Rick
>
>
> ---------------------------------------------------------------------
> 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: [solved] Revisiting nested Lists (again:) using Request scope ( also related to LazyList )

Posted by Tamas Szabo <sz...@gmail.com>.
On 12/30/05, Rick R <st...@reumann.net> wrote:
>
> Tamas Szabo wrote:
>
> > You will have to use a PhoneNumber object so you will have a reference
> to
> > employee[idx1].phoneNumbers[idx2].number in your html:text.
>
> Thanks Tamas!  That was exactly the problem. Typically I do exactly that
> and use lists of beans, but this time I thought I'd make the demo more
> simple by just having a List of Strings, but ironically that made it
> more difficult. I just built a Contact object instead to hold
> phoneNumber and now all is well.


Stack traces + open source libraries, frameworks are powerful together  ;-)


> Thanks again!


No worries!

Rick


Tamas

Re: [solved] Revisiting nested Lists (again:) using Request scope ( also related to LazyList )

Posted by Rick R <st...@reumann.net>.
Tamas Szabo wrote:

> You will have to use a PhoneNumber object so you will have a reference to
> employee[idx1].phoneNumbers[idx2].number in your html:text.  

Thanks Tamas!  That was exactly the problem. Typically I do exactly that 
and use lists of beans, but this time I thought I'd make the demo more 
simple by just having a List of Strings, but ironically that made it 
more difficult. I just built a Contact object instead to hold 
phoneNumber and now all is well.

Thanks again!

-- 
Rick


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


Re: Revisiting nested Lists (again:) using Request scope ( also related to LazyList )

Posted by Tamas Szabo <sz...@gmail.com>.
On 12/29/05, Rick R <st...@reumann.net> wrote:
>
> Tamas Szabo wrote:
>
> >> public void reset(ActionMapping actionMapping, HttpServletRequest
> >> httpServletRequest) {
> >>
> >>      employees = ListUtils.lazyList(new java.util.ArrayList(), new
> >> Factory() {
> >>          public Object create() {
> >>              return buildEmployee();
> >>          }
> >>      });
> >>   }
> >>
> >> private Employee buildEmployee() {
> >>     //This really isn't working,
> >>     //I'll still get  an index out of bounds, when
> >>     //trying to set an index of the phoneNumbers list
> >>      Employee emp = new Employee();
> >>      List phoneNumbers = ListUtils.lazyList(new java.util.ArrayList(),
> >> new Factory() {
> >>          public Object create() {
> >>              return new String();
> >>          }
> >>      });
> >>      emp.setPhoneNumbers( phoneNumbers );
> >>      return emp;
> >>
> >> }
> >
> >
> > I never used something like this before but I don't understand why
> wouldn't
> > this actually work if you have a nested LazyList.
> > Can we see a stack trace please?
>
> Sure....
>
> java.lang.IndexOutOfBoundsException: Index: 2, Size: 0
>         at java.util.ArrayList.RangeCheck(ArrayList.java:507)
>         at java.util.ArrayList.set(ArrayList.java:340)


Thanks, it's clear now.

I bet that you don't have don't have foo[idx1].bar[idx2].someProperty as in
your example
you just have employee[idx1].phoneNumbers[idx2] in your html:text's
property.

so form.getEmployee(idx1).setPhoneNumbers(idx2, textFieldValue) will be
called.

LazyList decorates only the get(int) method of your ArrayList, so you will
have no element at idx2 and that's why you got that IOOBE.

You will have to use a PhoneNumber object so you will have a reference to
employee[idx1].phoneNumbers[idx2].number in your html:text. That will lead
to
form.getEmployee(idx1).getPhoneNumbers(idx2).setNumber(textFieldValue) which
will fix your problem. You could add things like country code, prefix to
your PhoneNumber class to "justify" the use of a separate class :-)

Another possiblity is to write a Decorator around a List or subclass
LazyList and decorate the set(int, Object) method in the same way that the
get(int) is decorated.

Regards,
Tamas

Re: Revisiting nested Lists (again:) using Request scope ( also related to LazyList )

Posted by Rick R <st...@reumann.net>.
Tamas Szabo wrote:

>> public void reset(ActionMapping actionMapping, HttpServletRequest
>> httpServletRequest) {
>>
>>      employees = ListUtils.lazyList(new java.util.ArrayList(), new
>> Factory() {
>>          public Object create() {
>>              return buildEmployee();
>>          }
>>      });
>>   }
>>
>> private Employee buildEmployee() {
>>     //This really isn't working,
>>     //I'll still get  an index out of bounds, when
>>     //trying to set an index of the phoneNumbers list
>>      Employee emp = new Employee();
>>      List phoneNumbers = ListUtils.lazyList(new java.util.ArrayList(),
>> new Factory() {
>>          public Object create() {
>>              return new String();
>>          }
>>      });
>>      emp.setPhoneNumbers( phoneNumbers );
>>      return emp;
>>
>> }
> 
> 
> I never used something like this before but I don't understand why wouldn't
> this actually work if you have a nested LazyList.
> Can we see a stack trace please?

Sure....

java.lang.IndexOutOfBoundsException: Index: 2, Size: 0
	at java.util.ArrayList.RangeCheck(ArrayList.java:507)
	at java.util.ArrayList.set(ArrayList.java:340)
	at 
org.apache.commons.collections.list.AbstractListDecorator.set(AbstractListDecorator.java:97)
	at 
org.apache.commons.beanutils.PropertyUtilsBean.setIndexedProperty(PropertyUtilsBean.java:1417)
	at 
org.apache.commons.beanutils.BeanUtilsBean.setProperty(BeanUtilsBean.java:1016)
	at 
org.apache.commons.beanutils.BeanUtilsBean.populate(BeanUtilsBean.java:811)
	at org.apache.commons.beanutils.BeanUtils.populate(BeanUtils.java:298)
	at org.apache.struts.util.RequestUtils.populate(RequestUtils.java:493)
	at 
org.apache.struts.action.RequestProcessor.processPopulate(RequestProcessor.java:804)
	at 
org.apache.struts.action.RequestProcessor.process(RequestProcessor.java:203)
	at org.apache.struts.action.ActionServlet.process(ActionServlet.java:1196)
	at org.apache.struts.action.ActionServlet.doPost(ActionServlet.java:432)
	at javax.servlet.http.HttpServlet.service(HttpServlet.java:709)
	at javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
	at 
org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:237)
	at 
org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:157)
	at 
org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:214)
	at 
org.apache.catalina.core.StandardValveContext.invokeNext(StandardValveContext.java:104)
	at 
org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:520)
	at 
org.apache.catalina.core.StandardContextValve.invokeInternal(StandardContextValve.java:198)
	at 
org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:152)
	at 
org.apache.catalina.core.StandardValveContext.invokeNext(StandardValveContext.java:104)
	at 
org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:520)
	at 
org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:137)
	at 
org.apache.catalina.core.StandardValveContext.invokeNext(StandardValveContext.java:104)
	at 
org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:118)
	at 
org.apache.catalina.core.StandardValveContext.invokeNext(StandardValveContext.java:102)
	at 
org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:520)
	at 
org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
	at 
org.apache.catalina.core.StandardValveContext.invokeNext(StandardValveContext.java:104)
	at 
org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:520)
	at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:929)
	at org.apache.coyote.tomcat5.CoyoteAdapter.service(CoyoteAdapter.java:160)
	at 
org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:799)
	at 
org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.processConnection(Http11Protocol.java:705)
	at 
org.apache.tomcat.util.net.TcpWorkerThread.runIt(PoolTcpEndpoint.java:577)
	at 
org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadPool.java:683)
	at java.lang.Thread.run(Thread.java:534)


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


Re: Revisiting nested Lists (again:) using Request scope ( also related to LazyList )

Posted by Tamas Szabo <sz...@gmail.com>.
Hi!

On 12/29/05, Rick Reumann <st...@reumann.net> wrote:
>
> I'm still stumped with the best way to handle cases where your nesting
> goes a bit deeper than just into one list in your ActionForm (and you
> want to use Request scope for your ActionForm). Yes, I know many of you
> state that it means you have a complicated UI, but I've had numerous
> questions come to me personally about master-detail forms where you do
> edit several records from a single form, so I'm going to write up a
> tutorial on it.
>
> For example lets assume you want to edit on a single JSP a list of
> Employees - where you want to be able to edit their "name" AND "phone
> numbers":
>
> (imagine data below in editable text fields)
>
> Employee              Phone Numbers
> --------              -------------
> John Doe              888-888-8888
>                        888-111-1111
>                        222-222-2222
>
> Bill Boo              111-111-3333
>                        444-333-3333
>
>           [Submit Button]
>
>
> So we might have a List of Employee objects where Employee has:
>     String name;
>     List phoneNumbers;
>
> And our ActionForm bean thus has a single property:
>     List employees;
>
> Here's the problem.... in the reset method you can set a LazyList to
> wrap the Employees but there is still the problem of the internal List
> of phoneNumbers in each Employee.
>
> I was trying:
>
>   public void reset(ActionMapping actionMapping, HttpServletRequest
> httpServletRequest) {
>
>      employees = ListUtils.lazyList(new java.util.ArrayList(), new
> Factory() {
>          public Object create() {
>              return buildEmployee();
>          }
>      });
>   }
>
> private Employee buildEmployee() {
>     //This really isn't working,
>     //I'll still get  an index out of bounds, when
>     //trying to set an index of the phoneNumbers list
>      Employee emp = new Employee();
>      List phoneNumbers = ListUtils.lazyList(new java.util.ArrayList(),
> new Factory() {
>          public Object create() {
>              return new String();
>          }
>      });
>      emp.setPhoneNumbers( phoneNumbers );
>      return emp;
>
> }


I never used something like this before but I don't understand why wouldn't
this actually work if you have a nested LazyList.
Can we see a stack trace please?


Tamas