JSP page adds an array of collections to the action (commit with serialization)

Source: Internet
Author: User

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)

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.