My requirement is
I will have a JSP where emails for that particular user will be displayed
The user can select the mails which he wish to delete
On click of delete button the IDs of the check-box (which the user selected for deletion) has to be captured and given to server and the server in turn deletes it by running an HQL
Currently am handling this by joining the ids with pipe symbol and sending it in query-string as a single string object and in server side am tokenizing the ids and deleting it in iteration
below is the jquery script in which am joining the ids with pipe symbol
$("#deleteBtn").click(function() {
var deleteIDList = "" ;
$("[name='deleteCheckboxGroup']").each(function() {
if($(this).is(':checked')) {
var chckId = $(this).attr("id") ;
deleteIDList+=chckId.split("_")[0] +"|";
}
});
if (deleteIDList!="") {
// to remove pipe symbol from the last character, we are using 'slice' method of javascript
deleteIDList = deleteIDList.slice(0,-1) ;
var actionUrl = "deleteMessageText.htm?messageIDs="+deleteIDList ;
$("#studentMessFrm").attr("action",actionUrl) ;
$("#studentMessFrm").submit() ;
}else {
return false ;
}
}) ;
and this is how i tokenize and delete the object from DB
public void deleteMessages(String messageIDs) throws ReadsException{
//List<Long> deletedIdList = new ArrayList<Long>() ;
StringTokenizer stringTokenizer = new StringTokenizer(messageIDs,"|") ;
Map<String,Object> parameterMap = null ;
while (stringTokenizer.hasMoreTokens()) {
String query = "DELETE FROM MESSAGES MES WHERE MES.MESID=:MESID";
parameterMap = new HashMap<String,Object>();
parameterMap.put("MESID", Long.valueOf(stringTokenizer.nextToken()));
executeUpdateOrDelete(query, parameterMap);
}
LOGGER.info("deleted successfully..");
}
I know that this is unprofessional type of coding. I want the list of ids to be passed to MVC controller in requestParam and then the list ids should be deleted at "ONE SHOT".
Please suggest me on this. Thanks
Regards Arun