When I first load the form I want two empty rows and then I should be able to add more rows.
This is how I have my JSp page Login Name: <html:text property="login"/> <TABLE id="mytable"> <tr> <th>First Name</th> <th>Telephone Number</th> </tr> <logic:present name="personList"> <logic:iterate id="person" name="dynaTableForm" property="personList" type="com.learning.struts.PersonBean" scope="session" > <tr> <td> <input type="hidden" name="key" /> <html:text name="person" property="firstName" indexed="true"/> </td> <td> <html:text name="person" property="phoneNo" indexed="true"/> </td> </tr> </logic:iterate> </logic:present> </TABLE> <input type="button" name="addRow" value="Add Row" onClick="insertTableRow('mytable')"> <br> <table width="750" border="0" cellspacing="0" cellpadding="2"> <tr> <td align="middle"> <html:submit /> </td> </tr> </table> <% ArrayList arr=(ArrayList)request.getAttribute("personList"); System.out.println("ArraySize"+arr.size()); int cnt=arr.size(); %> <input type="hidden" value="<%=cnt%>" name="personListLength" > When I have a name in the Login Name text box the values in the table are repopulated in the form, but when I try to make the page fail with validation error then The table is not built persolList.size()=0. Do i need to take the form data and rebuild the Arraylist every time? If so then when it passes validation how is populatting the data.. This is how my form bean looks public class DyanTableForm extends ActionForm { private ArrayList personList; private String login=""; public void reset(ActionMapping mapping, HttpServletRequest request){ this.personList = new ArrayList(); String num = request.getParameter("personListLength"); //String num = "3"; try { if (num != null) { int len = Integer.parseInt(num); for (int i = 0; i < len; i++) this.personList.add(new PersonBean()); }else { this.personList.add(new PersonBean()); } }catch (NumberFormatException e) { e.printStackTrace(); } } public ActionErrors validate(ActionMapping mapping, HttpServletRequest request) { ActionErrors errors = new ActionErrors(); if ((login == null) || (login.length() < 1)) errors.add("Login", new ActionError("error.Login.required")); return errors; } public void setLogin(String newLogin) { login = newLogin; } public String getLogin() { return login; } public PersonBean getPerson(int ndx) { return (PersonBean) personList.get(ndx); } public void setPersonList(int ndx, PersonBean p) { personList.set(ndx, p); } public ArrayList getPersonList(){ return this.personList; } } The existing Data is editable in the text boxes. I did put the hidden value in the page --But I am doing something wrong here.. I am learning so pls bear with me.. Thanks >>> [EMAIL PROTECTED] 06/12/03 04:39PM >>> Are you still sticking things in the request manually or did you switch to the form? Only info you post in the form submission will come back to you when validation returns. I don't know if your existing data is editable in text boxes (in which case it would post and come back) or if you are displaying it with bean:write (or c:out...), in which case you would need to have hiddens for every piece of info you display. As for the personListLength (that is what you meant by the ArrayList size, right?), did you put it in a hidden as I suggested or manually stick it in the request from the prep? It will need to post like all the other info you want to still have upon return from validation. An alternate, of course, is to put the form in session scope, then everything will still be available when you return. -j -----Original Message----- From: Sashi Ravipati [mailto:[EMAIL PROTECTED] Sent: Thursday, June 12, 2003 12:59 PM To: [EMAIL PROTECTED] Subject: RE: what setters do i implementinan indexedtag--NewBiequestion John I am having a problem when the form Validation fails. The ArrayList is size is resetting to ZERO. The action errors are coming but the table with the data is not coming. Thanks >>> [EMAIL PROTECTED] 06/12/03 02:52PM >>> It's not the ArrayList that's the problem. The problem is getting blank PersonBeans into the ArrayList such that when the form is populated they are ready and waiting and you don't get the 'index out of bounds' bomb. -----Original Message----- From: Bailey, Shane C. [mailto:[EMAIL PROTECTED] Sent: Thursday, June 12, 2003 11:28 AM To: 'Struts Users Mailing List' Subject: RE: what setters do i implement inan indexedtag--NewBiequestion personList is an ArrayList. I thought they increased automagically. Maybe only my special Java code makes ArrayList increase for me without having to increase the size. :) -----Original Message----- From: Sashi Ravipati [mailto:[EMAIL PROTECTED] Sent: Thursday, June 12, 2003 2:33 PM To: [EMAIL PROTECTED] Subject: RE: what setters do i implement inan indexedtag--NewBiequestion Sorry for the post, I figured it out and got working. Only issues is to Increase the size of the personList when rows are added by user. Any ideas Thanks >>> [EMAIL PROTECTED] 06/12/03 02:25PM >>> > -----Original Message----- > From: Sashi Ravipati [mailto:[EMAIL PROTECTED] > > I had a question on how to do the prep action. > > [This assumes the prep action that entered the jsp figured out the size > of the list and set it into a hidden in the jsp in a field named > personListLength.] > > I tried like this but not sure if this is right > > In my action i added these lines > > ArrayList personList=new ArrayList(); > personList.add(new PersonBean()); > request.setAttribute("personList",personList); > return mapping.findForward("success"); > > I tried to retrieve it in the JSP page but did not get the value. I must > be doing something wrong. If it isn't working, then show us what you did, and show exactly what happened. It's hard for us to help if we don't know what you did. --------------------------------------------------------------------- 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] --------------------------------------------------------------------- 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] --------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]