Mark Lowe
Mon, 22 Mar 2004 05:42:56 -0800
import org.apache.struts.action.ActionMapping; import javax.servlet.http.*; import java.util.ArrayList; import java.util.List; import org.apache.struts.action.ActionForm; import org.apache.commons.collections.ListUtils; import org.apache.commons.collections.Factory;
public class ItemsForm extends ActionForm {
private List itemList; public ItemsForm() {
initLists();
}
private void initLists() {
Factory factory = new Factory() {
public Object create() {
return new ProductForm();
}
};
this.itemList = ListUtils.lazyList(new ArrayList(), factory);
} public List getItems() {
return itemList;
} public void setItems(List itemList) {
this.itemList = itemList;
} public ItemForm getItem(int index) {
return (ItemForm) itemList.get(index);
}
public void setItem(int index,ItemForm item) {
this.itemList.add(index,item);
} public void reset(ActionMapping mapping,
HttpServletRequest request) {
super.reset(mapping, request);
initLists();
}
}public class ItemForm extends ActionForm {
private String name; public String getName() {
return name;
} public void setName(String name) {
this.name = name;
}
}ItemForm item = new ItemForm();
item.setName("First Item");ItemForm anotherItem = new ItemForm();
anotherItem.setName("Second Item");theForm.setItem(0,item); theForm.setItem(1,item);
<html:form path="/save.do">
<logic:iterate id="item" name="itemsForm" property="items">
<html:text name="item" property="item" indexed="true" /> <c:forEach var="item" items="${itemsForm.items}">
<html:text name="item" property="item" indexed="true" />http://jakarta.apache.org/struts/faqs/indexedprops.html
-----Original Message----- From: Prakasan OK [mailto:[EMAIL PROTECTED] Sent: Monday, March 22, 2004 6:18 AM To: Struts Users Mailing List Subject: Indexed Property
Hi,
can anyone give me a sample code for implementing indexed properties? how should the jsp page and the corresponding Action class look like?
thanks, Prakasan
--------------------------------------------------------------------- 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]