On 12/29/05, Rick R <[EMAIL PROTECTED]> 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