JSP<HTML: Form styleid = "delform" Action = "/category. do? Method = deletecolletion ">
<Logic: iterate id = "category" name = "categories">
<Tr>
<TD <input type = "checkbox" name = "IDS" value = "<Bean: write name =" category "property =" ID "/>"> TD>
<TD>... </TD>
</Tr>
</Logic: iterate>
<Input type = "checkbox" name = "isselected" value = "true"
Onclick = "If (delform. isselected. Checked = true)
{For (VAR I = 0; I <delform. IDs. length; I ++) {delform. IDS [I]. Checked = true ;}}
Else {for (VAR I = 0; I <delform. IDs. length; I ++) {delform. IDS [I]. checked = false ;}}"/> select all & nbsp; <a href = "javascript: if (confirm ('Do you really want to delete the selected column? ') Delform. Submit () "> delete all selected columns </a>
</Html: Form>
Formbean(I am using dynaactionform, so configure it in the struts-config.xml)
<Form-bean name = "testingform" type = "org. Apache. Struts. Action. dynaactionform">
<Form-property name = "ID" type = "Java. Lang. String"/>
<Form-property name = "IDS" type = "Java. Lang. Long []"/>
........
</Form-bean>
Action Public actionforward execute (actionmapping mapping, actionform form,
Httpservletrequest request, httpservletresponse response)
Throws exception {
// Obtain the operation name
Dynaactionform LS-DYNA = (dynaactionform) form;
// IDs array is the ID value of all selected records
Long [] IDs = (long []) LS-DYNA. Get ("IDS ");
// Call the corresponding DAO method to delete all specified IDS
Return Mapping. findforward (".....");
}
Description
The key lies in the settings of formbean, that is, the array IDs. The general implementation method will traverse all the selected checkboxes on the client first, then assemble the string using JS and pass it to the action, parse the string in the background to get all the selected specified IDs. This method is not inappropriate, but it is simpler to use struts, here, we use the array attribute of a formbean to correspond to the checkbox DHTML array object on the page. Struts completes traversing all the checkboxes for us and finds out all the values of the selected checkbox. Is it simpler? Another thing I need to understand is that HTML: The Bean used by iterate and the formbean used for batch deletion are two different things. At first, I almost got confused.
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