It doesn't. What happens is, when Struts tries to access the nth bean
to populate it, the lazyList creates a bean and puts it at the nth
index.
Here's what I put in my ActionForm:
public class CollForm
extends ActionForm {
Collection accessDefinitions;
public Collection getAccessDefinitions() {
return accessDefinitions;
}
public void setAccessDefinitions(Collection accessDefinitions) {
this.accessDefinitions = accessDefinitions;
}
public void reset(ActionMapping mapping, HttpServletRequest request) {
super.reset(mapping, request);
accessDefinitions = ListUtils.lazyList(new java.util.ArrayList(),
new Factory() {
public Object create() {
return new AccessDefinition();
}
});
}
public static class AccessDefinition {
String name;
String description;
public AccessDefinition() { }
public AccessDefinition(String name, String description) {
this.name = name;
this.description = description;
}
public String getName() { return name; }
public void setName(String name) { this.name = name; }
public String getDescription() { return description; }
public void setDescription(String description) {
this.description = description; }
}
}
=========================
Here's what I have in my action to prepopulate it:
public ActionForward execute(ActionMapping mapping,
ActionForm actionForm,
HttpServletRequest request,
HttpServletResponse response)
throws Exception {
CollForm form = new CollForm();
form.reset(mapping, request);
Collection accessDefinitions = form.getAccessDefinitions();
accessDefinitions.add(new CollForm.AccessDefinition("http","internet"));
accessDefinitions.add(new CollForm.AccessDefinition("jms","messaging"));
form.setAccessDefinitions(accessDefinitions);
request.setAttribute("collForm", form);
return mapping.findForward("jsp");
}
=====================
If you use an actual factory class instead of the anonymous one I used
in CollForm.reset(), you won't have to call reset() in your Action,
just call ListUtils.lazyList() directly.
hth,
Hubert
On Thu, 02 Sep 2004 15:52:20 -0400, Rick Reumann <[EMAIL PROTECTED]> wrote:
> Hubert Rabago wrote:
>
> > Have you tried using ListUtils.lazyList() for this? I just tried it
> > on a sample app and it works in cases like this.
>
> No I haven't tried that. Even with that, how is the lazy load going to
> know the size to load without calling a business class behind the
> scenes? (which seems really goofy just to get a size).
>
>
>
> --
> Rick
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [EMAIL PROTECTED]
> For additional commands, e-mail: [EMAIL PROTECTED]
>
>
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]