struts2~列表~checkbox~删除多条记录方法介绍



struts2~列表~checkbox~删除多条记录方法介绍。jsp里~~

<script type = “text/javascript”>

function testDelete(){
flag=false;
len = testForm.delid.length;
for(i=0;i<len;i++){
if(testForm.delid[i].checked){
flag=true;
}
}
if(flag == false){
alert(“至少选择一个待删除记录”);
return false;
}

testForm.action = “../test/delete.action”;
testForm.submit();
}
</script>

<body>
<s:fielderror></s:fielderror>
<s:form theme = “simple” method = “post” name = “testForm”>
<table >
<input name=testDel” type=”button” value=”删除” onClick=”testDelete()”>
<s:iterator value=”testList” status=”st”>
<tr>
<td>
<s:hidden name = “testId”/>
<input name = “delid” type = “checkbox” value = “${testId}” id = “delid[#st.index]” >
</td>
<td><s:property value=”testName”></s:property></td>

</tr>
</s:iterator>
</table>
</body>


action里~~

private long[] delid = new long[]{};

public long[] getDelid() {
return delid;
}
public void setDelid(long[] delid) {
this.delid = delid;
}

public String deleteRecord() throws Exception {//删除记录
String idSting = “”;
for(int i=0;i<this.delid.length;i++){
idSting=idSting+this.delid[i]+”,”;
}
idSting=idSting.substring(0,idSting.length()-1);//待删除记录若干id的字符串,逗号分隔
testService.delete(idSting);
return SUCCESS;
}

http://blog.csdn.net/m13666368773/article/details/7086047