You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
@PostMapping("/owners/{ownerId}/edit")
public String processUpdateOwnerForm(@Valid Owner owner, BindingResult result, @PathVariable("ownerId") int ownerId,
RedirectAttributes redirectAttributes) {
if (result.hasErrors()) {
redirectAttributes.addFlashAttribute("error", "There was an error in updating the owner.");
return VIEWS_OWNER_CREATE_OR_UPDATE_FORM;
}
owner.setId(ownerId);
this.owners.save(owner);
redirectAttributes.addFlashAttribute("message", "Owner Values Updated");
return "redirect:/owners/{ownerId}";
}
Im looking this code.
if client want to see "There was an error in updating the owner.",
i think that return "redirect:/owners/{ownerId}";' is right, not VIEWS_OWNER_CREATE_OR_UPDATE_FORM;
I dont understand why use 'redirectAttributes.addFlashAttribute'
Maybe Spring developer probably has a specific intent.
Could you check this code?
The text was updated successfully, but these errors were encountered:
You are right that it is a mistake I think, but wrong about the return value - it is better to render the owner details directly if there is an error. The RedirectAttributes are discarded if the response is not a redirect, so the mistake is harmless. If anyone wants to fix it please reference this issue in the PR.
omelet3032
added a commit
to omelet3032/spring-petclinic
that referenced
this issue
May 29, 2024
Im looking this code.
if client want to see "There was an error in updating the owner.",
i think that return "redirect:/owners/{ownerId}";' is right, not VIEWS_OWNER_CREATE_OR_UPDATE_FORM;
I dont understand why use 'redirectAttributes.addFlashAttribute'
Maybe Spring developer probably has a specific intent.
Could you check this code?
The text was updated successfully, but these errors were encountered: