From f0b00da185b9e1e232c2e528132ebb457e011ed9 Mon Sep 17 00:00:00 2001 From: TejasM Date: Mon, 27 May 2013 14:28:24 -0400 Subject: [PATCH] Select Tag to validate pet type --- .../samples/petclinic/web/PetValidator.java | 2 ++ .../jsp/pets/createOrUpdatePetForm.jsp | 3 +-- src/main/webapp/WEB-INF/tags/selectField.tag | 23 +++++++++++++++++++ 3 files changed, 26 insertions(+), 2 deletions(-) create mode 100644 src/main/webapp/WEB-INF/tags/selectField.tag diff --git a/src/main/java/org/springframework/samples/petclinic/web/PetValidator.java b/src/main/java/org/springframework/samples/petclinic/web/PetValidator.java index 7068dd878..b47d02789 100644 --- a/src/main/java/org/springframework/samples/petclinic/web/PetValidator.java +++ b/src/main/java/org/springframework/samples/petclinic/web/PetValidator.java @@ -33,6 +33,8 @@ public class PetValidator { errors.rejectValue("name", "required", "required"); } else if (pet.isNew() && pet.getOwner().getPet(name, true) != null) { errors.rejectValue("name", "duplicate", "already exists"); + } else if (pet.isNew() && pet.getType() == null) { + errors.rejectValue("type", "required", "required"); } } diff --git a/src/main/webapp/WEB-INF/jsp/pets/createOrUpdatePetForm.jsp b/src/main/webapp/WEB-INF/jsp/pets/createOrUpdatePetForm.jsp index ee9c0a91e..6a740609c 100644 --- a/src/main/webapp/WEB-INF/jsp/pets/createOrUpdatePetForm.jsp +++ b/src/main/webapp/WEB-INF/jsp/pets/createOrUpdatePetForm.jsp @@ -42,8 +42,7 @@
- - +
diff --git a/src/main/webapp/WEB-INF/tags/selectField.tag b/src/main/webapp/WEB-INF/tags/selectField.tag new file mode 100644 index 000000000..f93256ac8 --- /dev/null +++ b/src/main/webapp/WEB-INF/tags/selectField.tag @@ -0,0 +1,23 @@ +<%@ taglib prefix="form" uri="http://www.springframework.org/tags/form" %> +<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %> +<%@ taglib prefix="spring" uri="http://www.springframework.org/tags" %> +<%@ attribute name="name" required="true" rtexprvalue="true" + description="Name of corresponding property in bean object" %> +<%@ attribute name="label" required="true" rtexprvalue="true" + description="Label appears in red color if input is considered as invalid after submission" %> +<%@ attribute name="names" required="true" rtexprvalue="true" type="java.util.List" + description="Names in the list" %> +<%@ attribute name="size" required="true" rtexprvalue="true" + description="Size of Select" %> + + + +
+ + +
+ + ${status.errorMessage} +
+
+
\ No newline at end of file