mirror of
https://github.com/spring-projects/spring-petclinic.git
synced 2025-07-15 12:25:50 +00:00
Select Tag to validate pet type
This commit is contained in:
parent
bca9c48e92
commit
f0b00da185
3 changed files with 26 additions and 2 deletions
|
@ -33,6 +33,8 @@ public class PetValidator {
|
||||||
errors.rejectValue("name", "required", "required");
|
errors.rejectValue("name", "required", "required");
|
||||||
} else if (pet.isNew() && pet.getOwner().getPet(name, true) != null) {
|
} else if (pet.isNew() && pet.getOwner().getPet(name, true) != null) {
|
||||||
errors.rejectValue("name", "duplicate", "already exists");
|
errors.rejectValue("name", "duplicate", "already exists");
|
||||||
|
} else if (pet.isNew() && pet.getType() == null) {
|
||||||
|
errors.rejectValue("type", "required", "required");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -42,8 +42,7 @@
|
||||||
<petclinic:inputField label="Name" name="name"/>
|
<petclinic:inputField label="Name" name="name"/>
|
||||||
<petclinic:inputField label="Birth Date" name="birthDate"/>
|
<petclinic:inputField label="Birth Date" name="birthDate"/>
|
||||||
<div class="control-group">
|
<div class="control-group">
|
||||||
<label class="control-label">Type </label>
|
<petclinic:selectField name="type" label="Type " names="${types}" size="5"/>
|
||||||
<form:select path="type" items="${types}" size="5"/>
|
|
||||||
</div>
|
</div>
|
||||||
<div class="form-actions">
|
<div class="form-actions">
|
||||||
<c:choose>
|
<c:choose>
|
||||||
|
|
23
src/main/webapp/WEB-INF/tags/selectField.tag
Normal file
23
src/main/webapp/WEB-INF/tags/selectField.tag
Normal file
|
@ -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" %>
|
||||||
|
|
||||||
|
<spring:bind path="${name}">
|
||||||
|
<c:set var="cssGroup" value="control-group ${status.error ? 'error' : '' }"/>
|
||||||
|
<div class="${cssGroup}">
|
||||||
|
<label class="control-label">${label}</label>
|
||||||
|
|
||||||
|
<div class="controls">
|
||||||
|
<form:select path="${name}" items="${names}" size="${size}"/>
|
||||||
|
<span class="help-inline">${status.errorMessage}</span>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</spring:bind>
|
Loading…
Reference in a new issue