Hi Richard, thanks a lot for your code. This works also fine with me (I tried that before) But if you switch from
<bean:write name="myObject" property="address"/> to <html:text name="myObject" property="address"/> and then submit these values to antoher form, or you change it and submit it to the same form, I get the beanutils. populate error. The output is always fine, but the input is a mess. I hope you also have a solution for this! Thanks a lot Michael -- Fehlerfreie Software wirkt weniger komplex und diskreditiert damit den Entwickler! ----- Original Message ----- From: "Richard Yee" <[EMAIL PROTECTED]> To: "Struts Users Mailing List" <[EMAIL PROTECTED]> Sent: Thursday, December 19, 2002 10:03 PM Subject: Re: beanutils.populate with formbeans and vectors > Michael, > This code works: > > TestActionForm.java > ------------------- > package com.test; > > import java.util.*; > import org.apache.struts.action.*; > > public class TestActionForm extends ActionForm > { > private ArrayList myItems = new ArrayList(); > public TestActionForm() > { > myItems.add(new MyObject("John Doe", "1 Main > St.")); > myItems.add(new MyObject("Jane Doe", "2 Main > St.")); > } > > public Collection getMyItems() { > return myItems; > } > > public void setMyItems(ArrayList items) { > myItems = items; > } > > public Object getItem(int index) { > if (index >= myItems.size()) > return new MyObject(); > return myItems.get(index); > > } > > /** > * setter for indexed property in myItems > */ > public void setMyItem(int index, Object value) { > int size=myItems.size(); > if (index >= size) { > for(int i=size; i<=index; i++) { > myItems.add(new MyObject()); > } > } > myItems.set(index,value); > } > } > > TestAction.java > --------------- > package com.test; > import org.apache.struts.action.Action; > import org.apache.struts.action.ActionForm; > import org.apache.struts.action.ActionForward; > import org.apache.struts.action.ActionMapping; > import org.apache.struts.action.ActionError; > import org.apache.struts.action.ActionErrors; > import java.io.IOException; > import java.util.Collection; > import java.util.Vector; > import javax.servlet.ServletException; > import javax.servlet.http.HttpServletRequest; > import javax.servlet.http.HttpServletResponse; > import javax.servlet.http.HttpSession; > > public class TestAction extends Action > { > /** > * This is the main action called from the Struts > framework. > * @param mapping The ActionMapping used to select > this instance. > * @param form The optional ActionForm bean for this > request. > * @param request The HTTP Request we are > processing. > * @param response The HTTP Response we are > processing. > */ > public ActionForward perform(ActionMapping mapping, > ActionForm form, HttpServletRequest request, > HttpServletResponse response) throws IOException, > ServletException > { > TestActionForm testForm = (TestActionForm) form; > System.out.println("TestAction.perform()"); > return mapping.findForward("success"); > } > } > > MyObject.java > ------------- > package com.test; > > import javax.servlet.http.HttpServletRequest; > import org.apache.struts.action.ActionForm; > import org.apache.struts.action.ActionError; > import org.apache.struts.action.ActionErrors; > import org.apache.struts.action.ActionMapping; > import org.apache.struts.upload.FormFile; > > public class MyObject > { > > private String name = null; > private String address = null; > > public MyObject() { > name = ""; > address = ""; > } > > public MyObject(String _name, String _address) > { > name = _name; > address = _address; > } > > /** > * getter method for name > */ > public String getName() { > return (name); > } > /** > * setter method for name > * @param - name; > */ > public void setName(String _name) { > name = _name; > } > > /** > * getter method for address > */ > public String getAddress() { > return (address); > } > /** > * setter method for address > * @param - address; > */ > public void setAddress(String _address) { > address = _address; > } > > public String toString() { > return name + ", " + address + "/n"; > } > } > > > > In the JSP page > > <logic:iterate name="testActionForm" > property="myItems" id="myObject"> > in iterate <bean:write name="myObject" property="name" > /> <bean:write name="myObject" property="address" > /><br> > </logic:iterate> > > The output: > in iterate John Doe 1 Main St. > in iterate Jane Doe 2 Main St. > > > Hope that helps, > > Richard > > > > > > > --- Michael Olszynski <[EMAIL PROTECTED]> wrote: > > I do it like this: > > > > <logic:iterate id="timeProofList" indexId="listIdx" > > name="timeProofForm" > > property="timeProofList"> > > <tr> > > <td> <html:text name="timeProofList" > > property="fromHour" indexed="true"/>: > > <html:text name="timeProofList" > > property="fromMinute" > > indexed="true"/> </td> > > </tr> > > </logic:iterate> > > > > -- > > Fehlerfreie Software wirkt weniger komplex und > > diskreditiert damit den > > Entwickler! > > ----- Original Message ----- > > From: "Richard Yee" <[EMAIL PROTECTED]> > > To: "Struts Users Mailing List" > > <[EMAIL PROTECTED]> > > Sent: Thursday, December 19, 2002 7:16 PM > > Subject: Re: beanutils.populate with formbeans and > > vectors > > > > > > > Michael, > > > How are you accessing the indexed property in the > > JSP? > > > > > > -Richard > > > > > > --- Michael Olszynski <[EMAIL PROTECTED]> > > wrote: > > > > Hi Richard, > > > > > > > > thanks again for your quick reply. I thought I > > need > > > > to subclass Vector, > > > > because I donīt save plain Strings in my Vector, > > I > > > > save Beans in it. So > > > > therefore I thought I need to have a polymorhism > > to > > > > save myself the work to > > > > write always indexed setters and getters . But > > > > anyway, I put the code you > > > > wrote me in my bean, and I still get errors. I > > give > > > > you a small snippet of > > > > my code (I tried to remove everything > > unnecessary) > > > > and I also attach the > > > > errormessage after the samplecode. Iīd really > > > > appreciate if you could look > > > > at it for a short moment. Thanks a lot > > > > > > > > Take care Michael > > > > > > > > > > **************************************************** > > > > public class TimeProofFormBean extends > > ActionForm { > > > > > > > > private Vector timeProofList = new Vector(); > > > > > > > > public Vector getTimeProofList() { > > > > return this.timeProofList; > > > > } > > > > > > > > public void setTimeProofList( Vector v ) { > > > > this.timeProofList = v; > > > > } > > > > > > > > > > > > /** > > > > * getter for indexed property in myFoos > > > > */ > > > > public Object getTimeProofList(int index) { > > > > if (index >= timeProofList.size()) > > > > return new TimeProofTableBean(); > > > > return timeProofList.get(index); > > > > } > > > > > > > > /** > > > > * setter for indexed property in myFoos > > > > */ > > > > public void setTimeProofList(int index, > > Object > > > > value) { > > > > int size=timeProofList.size(); > > > > if (index >= size) { > > > > for(int i=size; i<=index; i++) { > > > > timeProofList.add(new > > > > TimeProofTableBean()); > > > > } > > > > } > > > > timeProofList.set(index,value); > > > > } > > > > > > > > > > > > } > > > > > > > > > > ********************************************************** > > > > jsp page: > > > > <logic:iterate id="timeProofList" > > indexId="listIdx" > > > > name="timeProofForm" > > > > property="timeProofList"> > > > > <tr> > > > > <td> <html:text name="timeProofList" > > > > property="fromHour" size="2" > > > > maxlength="2" indexed="true"/>: > > > > <html:text name="timeProofList" > > > > property="fromMinute" size="2" > > > > maxlength="2" indexed="true"/> </td> > > > > </tr> > > > > </logic:iterate> > > > > > > > > > > **************************************************************** > > > > > > > > 18:35:35,684 ERROR [Engine] > > > > > > ApplicationDispatcher[/Zeiterfassung_Applikation] Se > > > > rvlet.service() for servlet jsp threw exception > > > > org.apache.jasper.JasperException: No getter > > method > > > > for property > > > > timeProofList o > > > > f bean timeProofForm > > > > at > > > > > > > > > > org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper > > > > .java:248) > > > > at > > > > > > > > > > org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:2 > > > > 89) > > > > at > > > > > > > > > > org.apache.jasper.servlet.JspServlet.service(JspServlet.java:240) > > > > at > > > > > > > > > > javax.servlet.http.HttpServlet.service(HttpServlet.java:853) > > > > at > > > > > > > > > > org.apache.catalina.core.ApplicationDispatcher.invoke(ApplicationDisp > > > > atcher.java:684) > > > > at > > > > > > > > > > org.apache.catalina.core.ApplicationDispatcher.doInclude(ApplicationD > > > > ispatcher.java:575) > > > > at > > > > > > > > > > org.apache.catalina.core.ApplicationDispatcher.include(ApplicationDis > > > > patcher.java:498) > > > > at > > > > > > > > > > org.apache.jasper.runtime.JspRuntimeLibrary.include(JspRuntimeLibrary > > > > .java:820) > > > > at > > > > > > > > > > org.apache.jasper.runtime.PageContextImpl.include(PageContextImpl.jav > > > > a:395) > > > > at > > > > > > > > > > org.apache.struts.taglib.template.GetTag.doStartTag(GetTag.java:191) > > > > at > > > > > > > > > > org.apache.jsp.template_jsp._jspx_meth_template_get_4(template_jsp.ja > > > > va:221) > > > > at > > > > > > > > > > org.apache.jsp.template_jsp._jspx_meth_html_html_0(template_jsp.java: > > > > 118) > > > > at > > > > > > > > > > org.apache.jsp.template_jsp._jspService(template_jsp.java:62) > > > > at > > > > > > > > > > org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:136) > > > > at > > > > > > > > > > javax.servlet.http.HttpServlet.service(HttpServlet.java:853) > > > === message truncated === > > > __________________________________________________ > Do you Yahoo!? > Yahoo! Mail Plus - Powerful. Affordable. Sign up now. > http://mailplus.yahoo.com > > -- > To unsubscribe, e-mail: <mailto:[EMAIL PROTECTED]> > For additional commands, e-mail: <mailto:[EMAIL PROTECTED]> > > -- To unsubscribe, e-mail: <mailto:[EMAIL PROTECTED]> For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>