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