Following is a basic example including my GenericFactory code. The lazyList
will adjust itself to grow even when an index outside the bounds of the
current collection is called. It also prepopulates the collection with the
object defined by the GenericFactory.
// Here is some basic ActionForm code using
// ListUtils.lazyList of the commons-collections
public class MyForm extends ActionForm {
Collection myList;
public MyForm() {
this.myList =
ListUtils.lazyList(
new ArrayList(),
new GenericFactory("com.foo.MyBean"));
}
public void setMyList(List myList) {
this.myList =
ListUtils.lazyList(
new ArrayList(myList),
new GenericFactory("com.foo.MyBean"));
}
public Collection getMyList() {
return myList;
}
}
// Here is the GenericFactory code
package com.foo.yourpackage;
import org.apache.commons.collections.Factory;
import org.apache.commons.logging.LogFactory;
import org.apache.commons.logging.Log;
public class GenericFactory implements Factory
{
private static final Log log = LogFactory.getLog(GenericFactory.class);
private String className;
private Object object;
public GenericFactory(String className)
{
this.className = className;
}
public Object create()
{
try
{
object = null;
Class classDefinition = Class.forName(className);
object = classDefinition.newInstance();
}
catch(InstantiationException ex)
{
log.error(ex.getMessage, ex.fillInStackTrace());
}
catch(IllegalAccessException ex)
{
log.error(ex.getMessage, ex.fillInStackTrace());
}
catch(ClassNotFoundException ex)
{
log.error(ex.getMessage, ex.fillInStackTrace());
}
return object;
}
}
Brandon Goodin
Can you elaborate? Or, point me to a decent example?
Thanks Brandon (and Hunter).
---------
Greg
"Brandon Goodin" <[EMAIL PROTECTED]> wrote in message
news:[EMAIL PROTECTED]
> ListUtils.lazyList of the commons-collections comes in handy here. Mix in
a
> good dose of jstl and/or nested tags and it should suffice.
>
> Brandon Goodin
>
> -----Original Message-----
> From: Greg Blomqusit [mailto:[EMAIL PROTECTED]
> Sent: Thursday, May 29, 2003 10:20 AM
> To: [EMAIL PROTECTED]
> Subject: Order Detail page with editable line items
>
>
> I have a problem that I'm sure is quite common. However, I have not seen
> any decent examples
> of how this might be implemented using Struts, so any suggestions would be
> greatly appreciated.
>
> The problem is this: I have an order detail page that has a list of line
> items with editable data
> inside each line item. The user is allowed to select which product
they're
> ordering and what quantity
> of that product per line item.
>
> I can figure out how to create an ActionForm bean that is able to convey
the
> values to the JSP
> using a collection of line item beans inside the ActionForm. And, I can
> figure out how to code
> the JSP to output the values into the form elements using the
> <logic:iterate> tag.
>
> However, what I'm having trouble with is submitting the values back to the
> Action. How can
> Struts repopulate the collection inside the ActionForm? Or, if I should
not
> be using a collection
> to represent the line items, how else should I do it? In the case of not
> using a collection to
> represent the line items, how do I get Struts taglib to populate the form
> elements in the JSP?
>
> I've attached a gif file that depicts the prototype of the screen I'm
> talking about, for those of you
> who are visual thinkers.
>
> Any help is appreciated!
>
> Thanks!
>
> -----------------
> Greg Blomquist
---------------------------------------------------------------------
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]