After implementing a JavaScript button action to push all checked elements on a jsp page into an array, the next step is passing this array to the controller class for further manipulation. Specifically, I need to be able to delete elements from that array within the controller function. How can this be achieved? The necessary components for achieving this task include the JavaScript function, JSP form, and controller class functions listed below.
<script type="text/javascript">
function selected(){
var all_checked = document.querySelectorAll('input[name=checkbox]:checked');
var selectedIds = [];
for(var x = 0, l = all_checked.length; x < l; x++)
{
selectedIds.push(all_checked[x].value);
}
return selectedIds;
}
</script>
> The selectedIds variable contains the checked items in the JSP page.
<form:form method="post" action="createnewstory/${userstoryId} }" modelAttribute="selectedIds" modelAttribute="fulluserstory">
... (remaining HTML code)
@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");
}
}
The goal is to retrieve the selectedIds array in the controller and store it as checkedlist array.