jspページ内のチェックされたすべての要素を配列にプッシュするJavaScriptボタンアクションを実装しました。したがって、この配列をコントローラークラスに渡す必要があります。コントローラー関数内でその配列の要素を削除する必要があります。どうすればいいですか?必要なのはpasだけですJavaScript関数、jspフォーム、コントローラークラスの関数は次のとおりです。
<script type="text/javascript">
function selected(){
var all_checked = document.querySelectorAll('input[name=checkbox]:checked');
//document.write(all_checked.length);
var selectedIds = [];
for(var x = 0, l = all_checked.length; x < l; x++)
{
selectedIds.push(all_checked[x].value);
//document.write(all_checked[x].value);
}
return selectedIds;
}
</script>
> selectedIds is containing the checked items in the jsp page.
<form:form method="post" action="createnewstory/${userstoryId} }" modelAttribute="selectedIds" modelAttribute="fulluserstory">
<div class="container">
<div class="deletebutton">
<input id="deleteAllButton" onClick="selected()" class="btn-lg btn-primary pull-right" type="submit" name="actionButton" value="Delete Selected"></input>
</div>
<div class="content">
<c:if test="${!empty storyList}">
<table class="table">
<thead>
<tr>
<th></th>
<th>User Story Id</th>
<th>User Story Name</th>
<th>Status</th>
</tr>
</thead>
<tbody>
<c:forEach items="${storyList}" var="userstory">
<tr>
<td class="checkbox"><input name="checkbox" type="checkbox" value="${userstory.userstoryId}" id="####" ></td>
<td class="uId"><c:out value="${userstory.userstoryId}"/></td>
<td class="uName">
<a href="<c:url value='/viewuserstory/${userstory.userstoryId}'/>"><c:out value="${userstory.userstoryname}"/></a>
</td>
<td class="uStatus"><c:out value="${userstory.status}"/></td>
</tr>
</c:forEach>
</tbody>
</table>
</c:if>
</div>
</div>
</form:form>
@RequestMapping(value="/createnewstory",method=RequestMethod.POST)
public String createNewStory(Map<String,Object> map,@ModelAttribute("fulluserstory") Fulluserstory fulluserstory,@RequestParam String actionButton,HttpServletRequest request){
if (actionButton.equals("Delete Selected")){
int [] checkedlist={73,74};
for(int i=0;i<checkedlist.length;i++){
int userstoryId=checkedlist[i];
userstoryService.delete(userstoryId);
System.out.println(checkedlist[i]);
System.out.println("delete#######selected inside for");
}
}
チェックリスト配列として、コントローラーでsetectedIds配列を取得する必要があります。
配列を文字列化できます
JSON.stringify(selectedIds);
コントローラで、これを文字列パラメータとして受け入れ、要件に基づいて配列またはリストに変換し直します。
ありがとう、ラビンドラ
この記事はインターネットから収集されたものであり、転載の際にはソースを示してください。
侵害の場合は、連絡してください[email protected]
コメントを追加