JS on the page
//Click on the A tab to add delete varI=0; $("#a"). On ("click",function(){ var$NEWTR = $ ("<tr id= ' model ' >" + "<td><input type= ' text ' name= ' contactslist[" +i+ "].c Ontactname ' value= ' ></td> ' + ' <td><input type= ' text ' name= ' contactslist[' +i+ ']. Contacttel ' value= ' ></td> ' + ' <td><input type= ' text ' name= ' contactslist[' +i+ ']. Contactfax ' value= ' ></td> ' + ' <td><input type= ' text ' name= ' contactslist[' +i+ ']. Contactemail ' value= ' ></td> ' + ' <td><input type= ' text ' name= ' contactslist[' +i+ '] . Contactrole ' value= ' ></td> ' + ' <td ><a href= ' javascript:void (0); ' class= ' del ' ; Delete </a></td> "+" </tr> "); I++; $newtr. Find (". Del"). Click (function(){ $( This). Parents ("tr"). Remove (); }); $("#fourdiv"). Append ($NEWTR); });
Page JSP
<DivID= "a"style= "Color:blue;cursor:pointer"><h4>Add a Contact</h4></Div> <DivID= "Thirddiv"> <TableID= "Fourdiv"> <TR> <th>Name</th> <th>Phone</th> <th>Fax</th> <th>Mailbox</th> <th>Duties</th> <th>Operation</th> </TR> </Table> </Div>
Receive directly in action with a collection (traversed as objects to add to the database)
PrivateList<contacts> contactslist =NewArraylist<contacts> ();//array of page receive contacts PublicList<contacts>getcontactslist () {returncontactslist; } Public voidSetcontactslist (list<contacts>contactslist) { This. contactslist =contactslist; } //add more than one contact for(Contacts contacts:contactslist) {Contacts.setcustomid (Customs.getid ()); This. customsservice.addcontacts (Contacts); }
JSP page adds an array of collections to the action (commit with serialization)