How can I get/set checkbox value using jstl and delete only those record from the database where the checkbox is checked? can you also advise how to use ternary operators in
Your checkbox has currently no value associated with the parameter name at all:
<input type="checkbox" name="chkBox">
So it's hard to find out the checked ones. You need to give the checkbox a value which uniquely identifies the selected item. In your particular example, the student ID seems to be an obvious choice:
<input type="checkbox" name="selected" value="${student.studentID}">
(by the way, why are you duplicating the entity name in the property name? why not just name it id
so that you can just self-documentary use ${student.id}
? also your var="students"
is kind of odd, it is referring only one student, so just name it var="student"
; the ${studentList}
can better be named ${students}
)
When the form is submitted, all checked value are available as follows:
String[] selectedStudentIds = request.getParameterValues("selected");
Finally, just pass it through to your DAO/service class which does the business job:
studentService.delete(selectedStudentIds);
this may help you.
In ajax call:
var boolValue= $(this).closest(".tr").find('.checkboxClass').is(':checked');
$.post("/api/dosomething", {
someSettings : boolValue
})