Reputation: 243
Trying to RequestMapping a submit, but I get this error, and I really dont understand why, because I thought everyone was provided :
There was an unexpected error (type=Bad Request, status=400).
Required Integer parameter 'idVac' is not present
[...]
function deleteRecord(idVac) {
var newwindow;
newwindow=window.confirm("Are you sure");
if(newwindow == true) {
alert("Condition is true");
var form = document.createElement("form");
form.setAttribute("name", "form");
form.setAttribute("method", "post");
form.setAttribute("action", "/vacEditDelete");
var vacancyId = document.createElement("input");
vacancyId.setAttribute("type", "hidden");
vacancyId.setAttribute("name", "vacancyId");
vacancyId.setAttribute("value", idVac);
var csrf = document.createElement("input");
csrf.setAttribute("type", "hidden");
csrf.setAttribute("name", "${_csrf.parameterName}");
csrf.setAttribute("value", "${_csrf.token}");
form.appendChild(csrf);
document.body.appendChild(form);
form.submit();
}
}
The method upon is mapping on this method in my Controller:
@RequestMapping(value = "/vacEditDelete", method = RequestMethod.POST)
public String deleteVacancy(@AuthenticationPrincipal User currentuser,
@RequestParam(value = "idVac", required = true) Integer idVac){
System.out.println("Method called");
vacService.deleteVacancyByID(idVac);
return "redirect:/vacEdit";
}
Upvotes: 0
Views: 5218
Reputation: 2417
in your code you are expecting @RequestParam(value = "idVac", required = true)
While in JS you are sending vacancyId.setAttribute("name", "vacancyId");
refer Spring Docs
Element Detail
value
public abstract String value
The name of the request parameter to bind to.
Default:
Upvotes: 1