mirror of
https://github.com/spring-projects/spring-petclinic.git
synced 2025-07-15 20:35:49 +00:00
set pet to owner to avoid null owner when user gets an error on new pet page
This commit is contained in:
parent
101c9dc690
commit
cdbfafe077
1 changed files with 1 additions and 1 deletions
|
@ -83,11 +83,11 @@ class PetController {
|
|||
if (StringUtils.hasLength(pet.getName()) && pet.isNew() && owner.getPet(pet.getName(), true) != null){
|
||||
result.rejectValue("name", "duplicate", "already exists");
|
||||
}
|
||||
owner.addPet(pet);
|
||||
if (result.hasErrors()) {
|
||||
model.put("pet", pet);
|
||||
return VIEWS_PETS_CREATE_OR_UPDATE_FORM;
|
||||
} else {
|
||||
owner.addPet(pet);
|
||||
this.pets.save(pet);
|
||||
return "redirect:/owners/{ownerId}";
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue