From cdbfafe0775079485edf50f5702ba300258239d1 Mon Sep 17 00:00:00 2001 From: Jeric Bryle Sy Dy <jeric@jericbryledy.com> Date: Fri, 9 Jun 2017 12:01:37 +0800 Subject: [PATCH] set pet to owner to avoid null owner when user gets an error on new pet page --- .../springframework/samples/petclinic/owner/PetController.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/org/springframework/samples/petclinic/owner/PetController.java b/src/main/java/org/springframework/samples/petclinic/owner/PetController.java index 0599faf..45b87c6 100644 --- a/src/main/java/org/springframework/samples/petclinic/owner/PetController.java +++ b/src/main/java/org/springframework/samples/petclinic/owner/PetController.java @@ -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}"; } -- GitLab