JSP Page :
<table width="30%" border="0">
<colgroup>
<COL width="5">
<COL width="30">
<COL width="30">
<COL width="35">
</colgroup>
<logic:iterate id="customer" name="listTextForm" property="customer">
<tr>
<td><html:checkbox name="customer" property="id" value="yes"/></td>
<td><html:text name="customer" property="firstName"
indexed="true"/></td>
<td><html:text name="customer" property="lastName"
indexed="true"/></td>
<td><html:text name="customer" property="address"
indexed="true"/></td>
</tr>
</logic:iterate>
<tr>
<td><input type="checkbox" name="id" value="yes"></td>
<td><input type="text" name="customer[4].firstName" value="John"></td>
<td><input type="text" name="customer[4].lastName" value="Mark"></td>
<td><input type="text" name="customer[4].address" value="New
York"></td>
</tr>
</table>
row is hardcoded (with index) on JSP page for simplicity. Now, on submit it
give me this error..
javax.servlet.ServletException: BeanUtils.populate
org.apache.struts.util.RequestUtils.populate(RequestUtils.java:495)
org.apache.struts.action.RequestProcessor.processPopulate(RequestProcessor.java:804)
org.apache.struts.action.RequestProcessor.process(RequestProcessor.java:203)
org.apache.struts.action.ActionServlet.process(ActionServlet.java:1196)
org.apache.struts.action.ActionServlet.doPost(ActionServlet.java:432)
javax.servlet.http.HttpServlet.service(HttpServlet.java:709)
javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
*root cause*
java.lang.ArrayIndexOutOfBoundsException
java.lang.reflect.Array.get(Native Method)
org.apache.struts.action.DynaActionForm.get(DynaActionForm.java:250)
org.apache.commons.beanutils.PropertyUtilsBean.getIndexedProperty(PropertyUtilsBean.java:386)
org.apache.commons.beanutils.PropertyUtilsBean.getIndexedProperty(PropertyUtilsBean.java:340)
org.apache.commons.beanutils.PropertyUtilsBean.getNestedProperty(PropertyUtilsBean.java:684)
org.apache.commons.beanutils.PropertyUtilsBean.getProperty(PropertyUtilsBean.java:715)
org.apache.commons.beanutils.BeanUtilsBean.setProperty(BeanUtilsBean.java:884)
org.apache.commons.beanutils.BeanUtilsBean.populate(BeanUtilsBean.java:811)
org.apache.commons.beanutils.BeanUtils.populate(BeanUtils.java:298)
org.apache.struts.util.RequestUtils.populate(RequestUtils.java:493)
org.apache.struts.action.RequestProcessor.processPopulate(RequestProcessor.java:804)
org.apache.struts.action.RequestProcessor.process(RequestProcessor.java:203)
org.apache.struts.action.ActionServlet.process(ActionServlet.java:1196)
org.apache.struts.action.ActionServlet.doPost(ActionServlet.java:432)
javax.servlet.http.HttpServlet.service(HttpServlet.java:709)
javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
Genetared HTML Code
<form name="listTextForm" method="post"
action="/GenerateHTMLTable/listtext.do">
<input type="submit" value="Submit">
<br>
<table width="30%" border="0">
<colgroup>
<COL width="5">
<COL width="30">
<COL width="30">
<COL width="35">
</colgroup>
<tr>
<td><input type="checkbox" name="id" value="yes"></td>
<td><input type="text" name="customer[0].firstName"
value="Irfan"></td>
<td><input type="text" name="customer[0].lastName"
value="Shaikh"></td>
<td><input type="text" name="customer[0].address" value="New
Mumbai"></td>
</tr>
<tr>
<td><input type="checkbox" name="id" value="yes"></td>
<td><input type="text" name="customer[1].firstName"
value="Maruf1212"></td>
<td><input type="text" name="customer[1].lastName"
value="Dolani"></td>
<td><input type="text" name="customer[1].address" value="Mumbai"></td>
</tr>
<tr>
<td><input type="checkbox" name="id" value="yes"></td>
<td><input type="text" name="customer[2].firstName"
value="Azima121111"></td>
<td><input type="text" name="customer[2].lastName"
value="Kacchi"></td>
<td><input type="text" name="customer[2].address" value="Pune"></td>
</tr>
<tr>
<td><input type="checkbox" name="id" value="yes"></td>
<td><input type="text" name="customer[3].firstName"
value="Ruhi11133"></td>
<td><input type="text" name="customer[3].lastName" value="Khan"></td>
<td><input type="text" name="customer[3].address" value="Pune"></td>
</tr>
<tr>
<td><input type="checkbox" name="id" value="yes"></td>
<td><input type="text" name="customer[4].firstName" value="John"></td>
<td><input type="text" name="customer[4].lastName" value="Mark"></td>
<td><input type="text" name="customer[4].address" value="New
York"></td>
</tr> <!--This is the HTML of hardcoded row-->
</table>
</form>
Thanks, waiting for reply.
On 12/19/05, atta-ur rehman <[EMAIL PROTECTED]> wrote:
>
> Irfan,
>
> By looking at the HTML source of the your page, please show me the name of
> textboxes added thru <logic:iterate> and name of the textboxes you've
> added
> thru Javascript.
>
> ATTA
>
>
> On 12/17/05, Irfan Shaikh <[EMAIL PROTECTED]> wrote:
> >
> > I am storing data objects into an Array for initial rows and when user
> > submit the form i am getting the updated values by using the code
> > highlighted below
> >
> > public ActionForward execute(ActionMapping mapping,
> > ActionForm form,
> > HttpServletRequest request,
> > HttpServletResponse response){
> >
> > DynaActionForm f = (DynaActionForm) form;
> > Customer[] s = (Customer[])f.get("customer");
> >
> > System.out.println("Number of Rows on page :" + s.length);
> >
> >
> > if (s.length!=0) {
> > insertAllCustomer(s);
> > f.set("customer", s);
> > } else {
> > Customer[] custArray = getAllCustomer();
> > f.set("customer", custArray);
> > }
> >
> > return (mapping.findForward("OK"));
> > }
> >
> > the problem here is when i populate the data on page for the first
> time
> > i
> > have 4 rows and then i add a new row by javascript, and i submit the
> page,
> > even then i get only 4 rows in execute method whereas i should get 5
> rows
> > so
> > that i can get the new added row data to create a new Customer bean and
> > put
> > it back to Customer[] array (this is my collection)
> >
> > Here is the loop for rows genration on JSP page :
> >
> > <logic:iterate id="customer" name="listTextForm" property="customer">
> > <tr>
> > <td><html:checkbox name="customer" property="id"
> value="yes"/></td>
> > <td><html:text name="customer" property="firstName" /></td>
> > <td><html:text name="customer" property="lastName" /></td>
> > <td><html:text name="customer" property="address" /></td>
> > </tr>
> > </logic:iterate>
> >
> >
> >
> > Is there something i am missing here ?... Waiting for a reply
> desperately
> > Thanks a lot.
> >
> > On 12/17/05, atta-ur rehman <[EMAIL PROTECTED]> wrote:
> > >
> > > Irfan,
> > >
> > > How are you storing data required for initial rows? As a collection of
> > > objects in some scope that <logic:iterate> uses to paint them on the
> > page?
> > >
> > > When user submits the page how are you getting the updated values?
> > > Populating the objects in the same collection or constructing a new
> > > collection and adding a object for each row?
> > >
> > > If that's the case, then all you need to do is reset the collection of
> > > objects to the new number of rows submitted by the user.
> > > Commons-Collection,
> > > which is required by Sturts(?) have a lazy-list which could be used
> for
> > > this
> > > purpose.
> > >
> > > ATTA
> > >
> > >
> > > On 12/16/05, Irfan Shaikh <[EMAIL PROTECTED]> wrote:
> > > >
> > > > Hi All,
> > > > I am new to Struts and need to implement a functionality
> > where
> > > a
> > > > new row is added to table (generated using logic:iterate tag on JSP
> > page
> > > )
> > > > on the fly(using javascript) and handling newly added row in
> > > > DynaActionForm
> > > > so that row gets saved to database. Need to know how to create a
> bean
> > > for
> > > > newly added row.
> > > >
> > > > Suggestion will be highly appreciated.
> > > > Thanks in advance
> > > >
> > > >
> > >
> > >
> >
> >
>
>