I have a profile page and an update page. First time I hit update I get the error messages, second time I hit update with all fields populated I get this error:
Completed 405 METHOD_NOT_ALLOWED
"ERROR" dispatch for POST "/error", parameters={multipart}
Here is the log:
2022-03-06 19:34:16.160 DEBUG 12260 --- [nio-8080-exec-8] o.s.w.s.v.ContentNegotiatingViewResolver : Selected 'text/html' given [text/html, application/xhtml+xml, image/avif, image/webp, image/apng, application/xml;q=0.9, application/signed-exchange;v=b3;q=0.9, *
The Controllers:
@GetMapping("/profile/update/{id}")
public String showUpdateForm(@PathVariable Long id, Model model) {
ProfileUpdateServiceModel updateServiceModel = this.userService.getProfileUpdateServiceModelById(id);
ProfileUpdateBindingModel updateBindingModel = this.mapper.map(updateServiceModel, ProfileUpdateBindingModel.class);
if (!model.containsAttribute("updateBindingModel")) {
model.addAttribute("updateBindingModel", updateBindingModel);
}
return "update-profile";
}
@PatchMapping("/profile/update/{id}")
public String update(@PathVariable Long id,@Valid ProfileUpdateBindingModel updateBindingModel, BindingResult br, RedirectAttributes rAtt){
if (br.hasErrors()) {
rAtt
.addFlashAttribute("updateBindingModel", updateBindingModel)
.addFlashAttribute("org.springframework.validation.BindingResult.updateBindingModel", br);
return "redirect:/users/profile/update/" + id;
}
return "redirect:/users/profile/" + id;
}
In profile.html I have a button like this:
<pre> <pre><form
th:method="GET"
th:action="@{/users/profile/update/{id}(id=*{userId})}">
<div class="col-md-6 offset-md-3 p-5">
<button type='submit' class="btn btn-primary">Update</button>
</div>
</form>
And in update-profile it is like this:
<div class="col-xl-6 col-md-12">
<form
th:object="${updateBindingModel}"
th:action="@{/users/profile/update/{id}(id=*{userId})}"
th:method="PATCH"
enctype="multipart/form-data">
What I have tried:
Whole day was researching about this but could not find much info. I think my get and post mappings match with those in the form. Not really sure what to look for.