You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by Irfan Shaikh <ir...@gmail.com> on 2005/12/16 16:28:19 UTC

Implementation of new row functionality of HTML table in Struts

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

Re: Implementation of new row functionality of HTML table in Struts

Posted by Irfan Shaikh <ir...@gmail.com>.
Hi guyz,
      Here is the solution for the issue we had

public class ListTextActionForm extends ActionForm {
   public List customer;

   public void setCustomer(List customer){
           this.customer = customer;
   }

   public List getCustomer() {
           return this.customer;
   }

   public void reset(ActionMapping mapping,HttpServletRequest request) {
           int count=0;
           String id ="";
        if (null!=this.customer) {
            System.out.println("List size1 :"+this.customer.size());
            int numRows = this.customer.size();
            while (null!=request.getParameter("customer["+ numRows +"].id"))
{
                    id = request.getParameter("customer["+numRows+"].id");
                    this.customer.add(new Customer(id,request.getParameter
("customer["+numRows+"].firstName"),request.getParameter
("customer["+numRows+"].lastName"),request.getParameter
("customer["+numRows+"].address"));
);
                    numRows++;
            }

          } else {
               System.out.println("List is Empty");
           }
   }
}

Put the new added row in to the ActioForm collection to create bean for the
added row.
Thanks
Irfan

Re: Implementation of new row functionality of HTML table in Struts

Posted by atta-ur rehman <at...@gmail.com>.
Irfan,

You might want to conclude this thread for future readers with similar
issues. Scope, problem and solutions that didn't work and the one that
finally worked might be helpful.

Just my 2 paisas!

ATTA


On 12/19/05, Irfan Shaikh <ir...@gmail.com> wrote:
>
> Thanks guyz, done with adding new row functionality. :)
>
>
> On 12/19/05, Irfan Shaikh <ir...@gmail.com> wrote:
> >
> > I am getting same error when i submit the form having newly added row.
> > Error is :
> >
> > 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.commons.beanutils.PropertyUtilsBean.getIndexedProperty(
> PropertyUtilsBean.java:437)
> >       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)
> >
> > Here is the reset() method:
> >
> >    public void reset(ActionMapping mapping,HttpServletRequest request) {
> >
> >               System.out.println("reset called");
> >               int count=0;
> >               if (null!=this.customer) {
> >                       String value = request.getParameter
> ("customer[0].firstName");
> >                       System.out.println("value :" + value);
> >
> >               if (value != null) {
> >                       while ((value = request.getParameter("customer[" +
> count + "].firstName")) != null) {
> >                            System.out.println("value :" + value);
> >
> >                            count++;
> >                       }
> >               }
> >
> >               Customer[] customers = new Customer[count];
> >               System.out.println("Customer[] size :"+customers.length);
> >               ListTextActionForm f = new ListTextActionForm();
> >
> >               f.setCustomer(customers);
> >
> >       } else {
> >                       System.out.println("Customer[] is null");
> >               }
> >    }
> >
> > No error arise  if no new row is added and code work fine.
> >
> >
> > Any solution to this issue
> > atta-ur rehman: Can i have ur msn/hotmail id for efficient conversation.
> >
> > Thanks
> >
> >
>
>

Re: Implementation of new row functionality of HTML table in Struts

Posted by Irfan Shaikh <ir...@gmail.com>.
Thanks guyz, done with adding new row functionality. :)


On 12/19/05, Irfan Shaikh <ir...@gmail.com> wrote:
>
> I am getting same error when i submit the form having newly added row.
> Error is :
>
> 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.commons.beanutils.PropertyUtilsBean.getIndexedProperty(PropertyUtilsBean.java:437)
> 	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)
>
> Here is the reset() method:
>
>    public void reset(ActionMapping mapping,HttpServletRequest request) {
>
>    		System.out.println("reset called");
>    		int count=0;	
> 		if (null!=this.customer) {
> 			String value = request.getParameter("customer[0].firstName");
> 			System.out.println("value :" + value);			
>
> 	     	if (value != null) {
> 	         	while ((value = request.getParameter("customer[" + count + "].firstName")) != null) {
> 	        	     System.out.println("value :" + value);
>
> 	        	     count++;
> 	         	}
> 	     	}	
> 	     	
> 	     	Customer[] customers = new Customer[count];
> 	     	System.out.println("Customer[] size :"+customers.length);
> 	     	ListTextActionForm f = new ListTextActionForm();
>
> 	     	f.setCustomer(customers);
> 	     	
>      	} else {
>    			System.out.println("Customer[] is null");
>    		}   		
>    }
>
> No error arise  if no new row is added and code work fine.
>
>
> Any solution to this issue
> atta-ur rehman: Can i have ur msn/hotmail id for efficient conversation.
>
> Thanks
>
>

Re: Implementation of new row functionality of HTML table in Struts

Posted by Irfan Shaikh <ir...@gmail.com>.
I am getting same error when i submit the form having newly added row.
Error is :

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.commons.beanutils.PropertyUtilsBean.getIndexedProperty(PropertyUtilsBean.java:437)
	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)

Here is the reset() method:

   public void reset(ActionMapping mapping,HttpServletRequest request) {
   		System.out.println("reset called");
   		int count=0;	
		if (null!=this.customer) {
			String value = request.getParameter("customer[0].firstName");
			System.out.println("value :" + value);			
	     	if (value != null) {
	         	while ((value = request.getParameter("customer[" + count +
"].firstName")) != null) {
	        	     System.out.println("value :" + value);
	        	     count++;
	         	}
	     	}	
	     	
	     	Customer[] customers = new Customer[count];
	     	System.out.println("Customer[] size :"+customers.length);
	     	ListTextActionForm f = new ListTextActionForm();
	     	f.setCustomer(customers);
	     	
     	} else {
   			System.out.println("Customer[] is null");
   		}   		
   }

No error arise  if no new row is added and code work fine.

Any solution to this issue
atta-ur rehman: Can i have ur msn/hotmail id for efficient conversation.

Thanks

Re: Implementation of new row functionality of HTML table in Struts

Posted by Irfan Shaikh <ir...@gmail.com>.
Not yet, let you know once done with that..
Thanks :)

On 12/19/05, atta-ur rehman <at...@gmail.com> wrote:
>
> so, have you been able to submit successfully?
>
> On 12/19/05, Irfan Shaikh <ir...@gmail.com> wrote:
> >
> > Uses the HTMLArray values to populate each cell of table.
> > Parameters :  eTable : Table which has to be processed
> >          HTMLArray : Array of HTML Components that need to be used in
> the
> > cells..
> >
> > function insertRow(eTable, HTMLArray, CellFocus) {
> >     // Insert the row and set the color etc.
> >     var eRow =  eTable.insertRow();
> >     eRow.bgcolor ="#0000ff";
> >
> >     //Take each cell and process it.
> >     for (i=0; i < HTMLArray.length; i++) {
> >         varCell = eRow.insertCell();
> >         varCell.bgColor = "#DAE9F8";
> >     //    varCell.align = "center";
> >         varCell.insertAdjacentHTML('afterBegin', HTMLArray[i]);
> >     }
> >
> >     //Finally set the focus to the recently added row. Note that focus
> is
> > returned to the First Cell in the row.
> >     //Assumption is that Cell(0) is the select Control. Cell(1) is where
> > the
> > user would like to start the data
> >     //entry.
> >     var NoOfRows = eTable.rows.length - 1;
> >     eTable.rows(NoOfRows).cells(CellFocus).childNodes(0).focus();
> > }
> >
> > On 12/19/05, JEEVANATHAM P. /BPCRP/INFOTECH/VASHI <
> > jeevanantham.p@3i-infotech.com> wrote:
> > >
> > > Same way I need to create a table and all fields are editable when
> user
> > > double clicks.
> > > Irfan can you tell me how can we create a new row using java script?
> > >
> > >
> > > -----Original Message-----
> > > From: Irfan Shaikh [mailto:irfan.rulz@gmail.com]
> > > Sent: Monday, December 19, 2005 1:12 PM
> > > To: Struts Users Mailing List
> > > Subject: Re: Implementation of new row functionality of HTML table in
> > > Struts
> > >
> > > No, user can add has many row he needed before submit... I had just
> > added
> > > one row to handle this scenario... It should work for as many row user
> > has
> > > added...
> > >
> > >
> > > On 12/19/05, atta-ur rehman <at...@gmail.com> wrote:
> > > >
> > > > okay, so you're saying use can add only ONE row dynamically before
> > > submit?
> > > > and that the newly added row's HTML code is:
> > > >
> > > > <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-->
> > > >
> > > >
> > > > if that's the case, in your ActionForm's reset method, detect that
> > user
> > > > has
> > > > added a new row, maybe thru request.getParameter
> > > ("customer[?].firstName")
> > > > where ? will be an integer 0..n where reuqest.getParameter would
> > return
> > > > null
> > > > for n+1. once you've done that do a:
> > > >
> > > > Customer[] customers = new Customer[n];
> > > > form.set("customer", customers);
> > > >
> > > > see if that helps.
> > > >
> > > > ATTA
> > > >
> > > >
> > > > On 12/18/05, Irfan Shaikh <ir...@gmail.com> wrote:
> > > > >
> > > > > Once again Generated HTML :
> > > > >
> > > > > <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>
> > > > >
> > > > >           <!--Session Scope -->
> > > > >
> > > > >         <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> (Hardcoded HTML row)
> > > > >
> > > > >   </table>
> > > > >
> > > > >
> > > > > </form>
> > > > >
> > > > >
> > > >
> > > >
> > >
> > > --
> > > Greetings!
> > >
> > >
> > >
> > >
> > > ICICI Infotech is now 3i Infotech.
> > >
> > >
> > > The e-mail addresses of the company's employees have been changed to
> > > <existing name>@3i-infotech.com. You are requested to take note of
> this
> > > new e-mail ID and make use of the same in future
> > >
> > >
> > > "This e-mail message may contain confidential, proprietary or legally
> > > privileged information. It should not be used by anyone who is not the
> > > original intended recipient. If you have erroneously received this
> > message,
> > > please delete it immediately and notify the sender. The recipient
> > > acknowledges that 3i Infotech or its subsidiaries and associated
> > companies,
> > > (collectively "3i Infotech"), are unable to exercise control or ensure
> > or
> > > guarantee the integrity of/over the contents of the information
> > contained in
> > > e-mail transmissions and further acknowledges that any views expressed
> > in
> > > this message are those of the individual sender and no binding nature
> of
> > the
> > > message shall be implied or assumed unless the sender does so
> expressly
> > with
> > > due authority of 3i Infotech. Before opening any attachments please
> > check
> > > them for viruses and defects."
> > >
> > >
> > >
> >
> >
>
>

Re: Implementation of new row functionality of HTML table in Struts

Posted by atta-ur rehman <at...@gmail.com>.
so, have you been able to submit successfully?

On 12/19/05, Irfan Shaikh <ir...@gmail.com> wrote:
>
> Uses the HTMLArray values to populate each cell of table.
> Parameters :  eTable : Table which has to be processed
>          HTMLArray : Array of HTML Components that need to be used in the
> cells..
>
> function insertRow(eTable, HTMLArray, CellFocus) {
>     // Insert the row and set the color etc.
>     var eRow =  eTable.insertRow();
>     eRow.bgcolor ="#0000ff";
>
>     //Take each cell and process it.
>     for (i=0; i < HTMLArray.length; i++) {
>         varCell = eRow.insertCell();
>         varCell.bgColor = "#DAE9F8";
>     //    varCell.align = "center";
>         varCell.insertAdjacentHTML('afterBegin', HTMLArray[i]);
>     }
>
>     //Finally set the focus to the recently added row. Note that focus is
> returned to the First Cell in the row.
>     //Assumption is that Cell(0) is the select Control. Cell(1) is where
> the
> user would like to start the data
>     //entry.
>     var NoOfRows = eTable.rows.length - 1;
>     eTable.rows(NoOfRows).cells(CellFocus).childNodes(0).focus();
> }
>
> On 12/19/05, JEEVANATHAM P. /BPCRP/INFOTECH/VASHI <
> jeevanantham.p@3i-infotech.com> wrote:
> >
> > Same way I need to create a table and all fields are editable when user
> > double clicks.
> > Irfan can you tell me how can we create a new row using java script?
> >
> >
> > -----Original Message-----
> > From: Irfan Shaikh [mailto:irfan.rulz@gmail.com]
> > Sent: Monday, December 19, 2005 1:12 PM
> > To: Struts Users Mailing List
> > Subject: Re: Implementation of new row functionality of HTML table in
> > Struts
> >
> > No, user can add has many row he needed before submit... I had just
> added
> > one row to handle this scenario... It should work for as many row user
> has
> > added...
> >
> >
> > On 12/19/05, atta-ur rehman <at...@gmail.com> wrote:
> > >
> > > okay, so you're saying use can add only ONE row dynamically before
> > submit?
> > > and that the newly added row's HTML code is:
> > >
> > > <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-->
> > >
> > >
> > > if that's the case, in your ActionForm's reset method, detect that
> user
> > > has
> > > added a new row, maybe thru request.getParameter
> > ("customer[?].firstName")
> > > where ? will be an integer 0..n where reuqest.getParameter would
> return
> > > null
> > > for n+1. once you've done that do a:
> > >
> > > Customer[] customers = new Customer[n];
> > > form.set("customer", customers);
> > >
> > > see if that helps.
> > >
> > > ATTA
> > >
> > >
> > > On 12/18/05, Irfan Shaikh <ir...@gmail.com> wrote:
> > > >
> > > > Once again Generated HTML :
> > > >
> > > > <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>
> > > >
> > > >           <!--Session Scope -->
> > > >
> > > >         <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> (Hardcoded HTML row)
> > > >
> > > >   </table>
> > > >
> > > >
> > > > </form>
> > > >
> > > >
> > >
> > >
> >
> > --
> > Greetings!
> >
> >
> >
> >
> > ICICI Infotech is now 3i Infotech.
> >
> >
> > The e-mail addresses of the company's employees have been changed to
> > <existing name>@3i-infotech.com. You are requested to take note of this
> > new e-mail ID and make use of the same in future
> >
> >
> > "This e-mail message may contain confidential, proprietary or legally
> > privileged information. It should not be used by anyone who is not the
> > original intended recipient. If you have erroneously received this
> message,
> > please delete it immediately and notify the sender. The recipient
> > acknowledges that 3i Infotech or its subsidiaries and associated
> companies,
> > (collectively "3i Infotech"), are unable to exercise control or ensure
> or
> > guarantee the integrity of/over the contents of the information
> contained in
> > e-mail transmissions and further acknowledges that any views expressed
> in
> > this message are those of the individual sender and no binding nature of
> the
> > message shall be implied or assumed unless the sender does so expressly
> with
> > due authority of 3i Infotech. Before opening any attachments please
> check
> > them for viruses and defects."
> >
> >
> >
>
>

Re: Implementation of new row functionality of HTML table in Struts

Posted by Irfan Shaikh <ir...@gmail.com>.
Uses the HTMLArray values to populate each cell of table.
Parameters :  eTable : Table which has to be processed
         HTMLArray : Array of HTML Components that need to be used in the
cells..

function insertRow(eTable, HTMLArray, CellFocus) {
    // Insert the row and set the color etc.
    var eRow =  eTable.insertRow();
    eRow.bgcolor ="#0000ff";

    //Take each cell and process it.
    for (i=0; i < HTMLArray.length; i++) {
        varCell = eRow.insertCell();
        varCell.bgColor = "#DAE9F8";
    //    varCell.align = "center";
        varCell.insertAdjacentHTML('afterBegin', HTMLArray[i]);
    }

    //Finally set the focus to the recently added row. Note that focus is
returned to the First Cell in the row.
    //Assumption is that Cell(0) is the select Control. Cell(1) is where the
user would like to start the data
    //entry.
    var NoOfRows = eTable.rows.length - 1;
    eTable.rows(NoOfRows).cells(CellFocus).childNodes(0).focus();
}

On 12/19/05, JEEVANATHAM P. /BPCRP/INFOTECH/VASHI <
jeevanantham.p@3i-infotech.com> wrote:
>
> Same way I need to create a table and all fields are editable when user
> double clicks.
> Irfan can you tell me how can we create a new row using java script?
>
>
> -----Original Message-----
> From: Irfan Shaikh [mailto:irfan.rulz@gmail.com]
> Sent: Monday, December 19, 2005 1:12 PM
> To: Struts Users Mailing List
> Subject: Re: Implementation of new row functionality of HTML table in
> Struts
>
> No, user can add has many row he needed before submit... I had just added
> one row to handle this scenario... It should work for as many row user has
> added...
>
>
> On 12/19/05, atta-ur rehman <at...@gmail.com> wrote:
> >
> > okay, so you're saying use can add only ONE row dynamically before
> submit?
> > and that the newly added row's HTML code is:
> >
> > <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-->
> >
> >
> > if that's the case, in your ActionForm's reset method, detect that user
> > has
> > added a new row, maybe thru request.getParameter
> ("customer[?].firstName")
> > where ? will be an integer 0..n where reuqest.getParameter would return
> > null
> > for n+1. once you've done that do a:
> >
> > Customer[] customers = new Customer[n];
> > form.set("customer", customers);
> >
> > see if that helps.
> >
> > ATTA
> >
> >
> > On 12/18/05, Irfan Shaikh <ir...@gmail.com> wrote:
> > >
> > > Once again Generated HTML :
> > >
> > > <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>
> > >
> > >           <!--Session Scope -->
> > >
> > >         <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> (Hardcoded HTML row)
> > >
> > >   </table>
> > >
> > >
> > > </form>
> > >
> > >
> >
> >
>
> --
> Greetings!
>
>
>
>
> ICICI Infotech is now 3i Infotech.
>
>
> The e-mail addresses of the company's employees have been changed to
> <existing name>@3i-infotech.com. You are requested to take note of this
> new e-mail ID and make use of the same in future
>
>
> "This e-mail message may contain confidential, proprietary or legally
> privileged information. It should not be used by anyone who is not the
> original intended recipient. If you have erroneously received this message,
> please delete it immediately and notify the sender. The recipient
> acknowledges that 3i Infotech or its subsidiaries and associated companies,
> (collectively "3i Infotech"), are unable to exercise control or ensure or
> guarantee the integrity of/over the contents of the information contained in
> e-mail transmissions and further acknowledges that any views expressed in
> this message are those of the individual sender and no binding nature of the
> message shall be implied or assumed unless the sender does so expressly with
> due authority of 3i Infotech. Before opening any attachments please check
> them for viruses and defects."
>
>
>

Re: Implementation of new row functionality of HTML table in Struts

Posted by atta-ur rehman <at...@gmail.com>.
I think, ArrayIndexOutOfBoundsException actually shows that changes to the
DOM are being submitted.

ATTA

On 12/19/05, Michael Jouravlev <jm...@gmail.com> wrote:
>
> On 12/18/05, Irfan Shaikh <ir...@gmail.com> wrote:
> > No, user can add has many row he needed before submit... I had just
> added
> > one row to handle this scenario... It should work for as many row user
> has
> > added...
>
> I would start from verifying that browser sends all rows to the
> server. If you use Firefox, you can install LiveHTTPHeaders extension.
> It might happen that your DOM changes are incorrect somewhere.
>
> Michael.
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
> For additional commands, e-mail: user-help@struts.apache.org
>
>

Re: Implementation of new row functionality of HTML table in Struts

Posted by Michael Jouravlev <jm...@gmail.com>.
On 12/18/05, Irfan Shaikh <ir...@gmail.com> wrote:
> No, user can add has many row he needed before submit... I had just added
> one row to handle this scenario... It should work for as many row user has
> added...

I would start from verifying that browser sends all rows to the
server. If you use Firefox, you can install LiveHTTPHeaders extension.
It might happen that your DOM changes are incorrect somewhere.

Michael.

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org


Re: Implementation of new row functionality of HTML table in Struts

Posted by atta-ur rehman <at...@gmail.com>.
now i understand you're renaming the dynamically added textboxes thru
Javascript? right? if that's the case your renaming looks good to me. can
you do the trick in the form's reset() method; that is, set the a new
Customer array to the forms's property with something like:

String value = request.getParameter("customer[0].firstName");

      if (value != null) {
          int count = 1;
          while ((value = request.getParameter("customer[" + count +
"].firstName")) != null) {
              count++;
          }
      }

      Customer[] customers = new Customer[count];
      f.set("customer", customers);


On 12/18/05, Irfan Shaikh <ir...@gmail.com> wrote:
>
> No, user can add has many row he needed before submit... I had just added
> one row to handle this scenario... It should work for as many row user has
> added...
>
>
> On 12/19/05, atta-ur rehman <at...@gmail.com> wrote:
> >
> > okay, so you're saying use can add only ONE row dynamically before
> submit?
> > and that the newly added row's HTML code is:
> >
> > <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-->
> >
> >
> > if that's the case, in your ActionForm's reset method, detect that user
> > has
> > added a new row, maybe thru request.getParameter
> ("customer[?].firstName")
> > where ? will be an integer 0..n where reuqest.getParameter would return
> > null
> > for n+1. once you've done that do a:
> >
> > Customer[] customers = new Customer[n];
> > form.set("customer", customers);
> >
> > see if that helps.
> >
> > ATTA
> >
> >
> > On 12/18/05, Irfan Shaikh <ir...@gmail.com> wrote:
> > >
> > > Once again Generated HTML :
> > >
> > > <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>
> > >
> > >           <!--Session Scope -->
> > >
> > >         <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> (Hardcoded HTML row)
> > >
> > >   </table>
> > >
> > >
> > > </form>
> > >
> > >
> >
> >
>
>

RE: Implementation of new row functionality of HTML table in Struts

Posted by "JEEVANATHAM P. /BPCRP/INFOTECH/VASHI" <je...@3i-infotech.com>.
Same way I need to create a table and all fields are editable when user
double clicks.
Irfan can you tell me how can we create a new row using java script?


-----Original Message-----
From: Irfan Shaikh [mailto:irfan.rulz@gmail.com] 
Sent: Monday, December 19, 2005 1:12 PM
To: Struts Users Mailing List
Subject: Re: Implementation of new row functionality of HTML table in Struts

No, user can add has many row he needed before submit... I had just added
one row to handle this scenario... It should work for as many row user has
added...


On 12/19/05, atta-ur rehman <at...@gmail.com> wrote:
>
> okay, so you're saying use can add only ONE row dynamically before submit?
> and that the newly added row's HTML code is:
>
> <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-->
>
>
> if that's the case, in your ActionForm's reset method, detect that user
> has
> added a new row, maybe thru request.getParameter("customer[?].firstName")
> where ? will be an integer 0..n where reuqest.getParameter would return
> null
> for n+1. once you've done that do a:
>
> Customer[] customers = new Customer[n];
> form.set("customer", customers);
>
> see if that helps.
>
> ATTA
>
>
> On 12/18/05, Irfan Shaikh <ir...@gmail.com> wrote:
> >
> > Once again Generated HTML :
> >
> > <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>
> >
> >           <!--Session Scope -->
> >
> >         <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> (Hardcoded HTML row)
> >
> >   </table>
> >
> >
> > </form>
> >
> >
>
>

-- 
Greetings!

 


ICICI Infotech is now 3i Infotech.


The e-mail addresses of the company's employees have been changed to <existing name>@3i-infotech.com. You are requested to take note of this new e-mail ID and make use of the same in future

 
"This e-mail message may contain confidential, proprietary or legally privileged information. It should not be used by anyone who is not the original intended recipient. If you have erroneously received this message, please delete it immediately and notify the sender. The recipient acknowledges that 3i Infotech or its subsidiaries and associated companies, (collectively "3i Infotech"), are unable to exercise control or ensure or guarantee the integrity of/over the contents of the information contained in e-mail transmissions and further acknowledges that any views expressed in this message are those of the individual sender and no binding nature of the message shall be implied or assumed unless the sender does so expressly with due authority of 3i Infotech. Before opening any attachments please check them for viruses and defects."


Re: Implementation of new row functionality of HTML table in Struts

Posted by Irfan Shaikh <ir...@gmail.com>.
No, user can add has many row he needed before submit... I had just added
one row to handle this scenario... It should work for as many row user has
added...


On 12/19/05, atta-ur rehman <at...@gmail.com> wrote:
>
> okay, so you're saying use can add only ONE row dynamically before submit?
> and that the newly added row's HTML code is:
>
> <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-->
>
>
> if that's the case, in your ActionForm's reset method, detect that user
> has
> added a new row, maybe thru request.getParameter("customer[?].firstName")
> where ? will be an integer 0..n where reuqest.getParameter would return
> null
> for n+1. once you've done that do a:
>
> Customer[] customers = new Customer[n];
> form.set("customer", customers);
>
> see if that helps.
>
> ATTA
>
>
> On 12/18/05, Irfan Shaikh <ir...@gmail.com> wrote:
> >
> > Once again Generated HTML :
> >
> > <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>
> >
> >           <!--Session Scope -->
> >
> >         <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> (Hardcoded HTML row)
> >
> >   </table>
> >
> >
> > </form>
> >
> >
>
>

Re: Implementation of new row functionality of HTML table in Struts

Posted by atta-ur rehman <at...@gmail.com>.
okay, so you're saying use can add only ONE row dynamically before submit?
and that the newly added row's HTML code is:

<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-->


if that's the case, in your ActionForm's reset method, detect that user has
added a new row, maybe thru request.getParameter("customer[?].firstName")
where ? will be an integer 0..n where reuqest.getParameter would return null
for n+1. once you've done that do a:

Customer[] customers = new Customer[n];
form.set("customer", customers);

see if that helps.

ATTA


On 12/18/05, Irfan Shaikh <ir...@gmail.com> wrote:
>
> Once again Generated HTML :
>
> <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>
>
>           <!--Session Scope -->
>
>         <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> (Hardcoded HTML row)
>
>   </table>
>
>
> </form>
>
>

Re: Implementation of new row functionality of HTML table in Struts

Posted by Irfan Shaikh <ir...@gmail.com>.
Once again Generated HTML :

<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>

	  <!--Session Scope -->

	<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> (Hardcoded HTML row)

  </table>


</form>

Re: Implementation of new row functionality of HTML table in Struts

Posted by Irfan Shaikh <ir...@gmail.com>.
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 <at...@gmail.com> 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 <ir...@gmail.com> 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 <at...@gmail.com> 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 <ir...@gmail.com> 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
> > > >
> > > >
> > >
> > >
> >
> >
>
>

Re: Implementation of new row functionality of HTML table in Struts

Posted by atta-ur rehman <at...@gmail.com>.
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 <ir...@gmail.com> 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 <at...@gmail.com> 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 <ir...@gmail.com> 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
> > >
> > >
> >
> >
>
>

Re: Implementation of new row functionality of HTML table in Struts

Posted by Irfan Shaikh <ir...@gmail.com>.
Thanks for the reply Michael,

   1. Yes, I am adding a row into the browser's DOM. Basically, client
   requirement is to implement a table like structure where user can add a new
   row to save new record. i need to know how to handle scenario where client
   changes (adding a new row) gets notified to server to create a new bean for
   the added row.
    2. I am submitting all rows because any changes to existing should
   get udpated to database.

Suggestion will be greatly appreciated. Thanks once again.

Irfan.


On 12/18/05, Michael Jouravlev <jm...@gmail.com> wrote:
>
> On 12/17/05, Irfan Shaikh <ir...@gmail.com> wrote:
> >    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
>
> Do you add a row right into the browser's DOM?
>
> >, and i submit the page,
> > even then i get only 4 rows in execute method whereas i should get 5
> rows
>
> You submit *all* rows back? What for? Why don't you want to submit
> only a new row? Does this look like something you would like to do:
> http://superinterface.com/strutsdialog/crudactionlite.do or is too
> simplistic for your tastes?
>
> Michael.
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
> For additional commands, e-mail: user-help@struts.apache.org
>
>

Re: Implementation of new row functionality of HTML table in Struts

Posted by Michael Jouravlev <jm...@gmail.com>.
On 12/17/05, Irfan Shaikh <ir...@gmail.com> wrote:
>    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

Do you add a row right into the browser's DOM?

>, and i submit the page,
> even then i get only 4 rows in execute method whereas i should get 5 rows

You submit *all* rows back? What for? Why don't you want to submit
only a new row? Does this look like something you would like to do:
http://superinterface.com/strutsdialog/crudactionlite.do or is too
simplistic for your tastes?

Michael.

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org


Re: Implementation of new row functionality of HTML table in Struts

Posted by Irfan Shaikh <ir...@gmail.com>.
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 <at...@gmail.com> 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 <ir...@gmail.com> 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
> >
> >
>
>

Re: Implementation of new row functionality of HTML table in Struts

Posted by atta-ur rehman <at...@gmail.com>.
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 <ir...@gmail.com> 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
>
>