diff --git a/src/main/java/org/springframework/samples/petclinic/Visit.java b/src/main/java/org/springframework/samples/petclinic/Visit.java index 30b38b412a9459f251592e72d261da3ba54cfc81..72227ae06a3bae55d6a3cd4c026e1d9d07503b4b 100644 --- a/src/main/java/org/springframework/samples/petclinic/Visit.java +++ b/src/main/java/org/springframework/samples/petclinic/Visit.java @@ -5,10 +5,9 @@ import javax.persistence.Entity; import javax.persistence.JoinColumn; import javax.persistence.ManyToOne; import javax.persistence.Table; -import javax.validation.constraints.NotNull; -import javax.validation.constraints.Size; import org.hibernate.annotations.Type; +import org.hibernate.validator.constraints.NotEmpty; import org.joda.time.DateTime; import org.springframework.format.annotation.DateTimeFormat; @@ -27,7 +26,7 @@ public class Visit extends BaseEntity { private DateTime date; /** Holds value of property description. */ - @NotNull @Size(min = 1) + @NotEmpty @Column(name="description") private String description; diff --git a/src/main/webapp/WEB-INF/jsp/owners/createOrUpdateOwnerForm.jsp b/src/main/webapp/WEB-INF/jsp/owners/createOrUpdateOwnerForm.jsp index 87025b8053347634dcdb413b78ce4eddc398a4ba..043814eaa5706fabd980d6c1e53c013a0a19b15e 100644 --- a/src/main/webapp/WEB-INF/jsp/owners/createOrUpdateOwnerForm.jsp +++ b/src/main/webapp/WEB-INF/jsp/owners/createOrUpdateOwnerForm.jsp @@ -3,6 +3,7 @@ <%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %> <%@ taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions" %> <%@ taglib prefix="form" uri="http://www.springframework.org/tags/form" %> +<%@ taglib prefix="petclinic" tagdir="/WEB-INF/tags" %> <html lang="en"> @@ -21,68 +22,22 @@ <c:if test="${owner['new']}">New </c:if> Owner </h2> <form:form modelAttribute="owner" method="${method}" class="form-horizontal" id="add-owner-form"> - <fieldset> - <spring:bind path="firstName"> - <c:set var="cssGroup" value="control-group ${status.error ? 'error' : '' }"/> - <div class="${cssGroup}" id="${firstName}"> - <label class="control-label">First Name</label> - <div class="controls"> - <form:input path="firstName"/> - <span class="help-inline">${status.errorMessage}</span> - </div> - </div> - </spring:bind> - <spring:bind path="firstName"> - <c:set var="cssGroup" value="control-group ${status.error ? 'error' : '' }"/> - <div class="${cssGroup}" id="${lastName}"> - <label class="control-label">Last Name</label> - <div class="controls"> - <form:input path="lastName"/> - <span class="help-inline">${status.errorMessage}</span> - </div> - </div> - </spring:bind> - <spring:bind path="address"> - <c:set var="cssGroup" value="control-group ${status.error ? 'error' : '' }"/> - <div class="${cssGroup}" id="${address}"> - <label class="control-label">Address</label> - <div class="controls"> - <form:input path="address"/> - <span class="help-inline">${status.errorMessage}</span> - </div> - </div> - </spring:bind> - <spring:bind path="city"> - <c:set var="cssGroup" value="control-group ${status.error ? 'error' : '' }"/> - <div class="${cssGroup}" id="${city}"> - <label class="control-label">City</label> - <div class="controls"> - <form:input path="city"/> - <span class="help-inline">${status.errorMessage}</span> - </div> - </div> - </spring:bind> - <spring:bind path="telephone"> - <c:set var="cssGroup" value="control-group ${status.error ? 'error' : '' }"/> - <div class="${cssGroup}" id="${telephone}"> - <label class="control-label">Telephone</label> - <div class="controls"> - <form:input path="telephone"/> - <span class="help-inline">${status.errorMessage}</span> - </div> - </div> - </spring:bind> - <div class="form-actions"> - <c:choose> - <c:when test="${owner['new']}"> - <button type="submit">Add Owner</button> - </c:when> - <c:otherwise> - <button type="submit">Update Owner</button> - </c:otherwise> - </c:choose> - </div> - </fieldset> + <petclinic:inputField label="First Name" name="firstName" /> + <petclinic:inputField label="Last Name" name="lastName" /> + <petclinic:inputField label="Address" name="address" /> + <petclinic:inputField label="City" name="city" /> + <petclinic:inputField label="Telephone" name="telephone" /> + + <div class="form-actions"> + <c:choose> + <c:when test="${owner['new']}"> + <button type="submit">Add Owner</button> + </c:when> + <c:otherwise> + <button type="submit">Update Owner</button> + </c:otherwise> + </c:choose> + </div> </form:form> </div> <jsp:include page="../fragments/footer.jsp"/> diff --git a/src/main/webapp/WEB-INF/jsp/pets/createOrUpdatePetForm.jsp b/src/main/webapp/WEB-INF/jsp/pets/createOrUpdatePetForm.jsp index 80042eec6efee6479703e8bbb89dada5f1fd4451..8e114c3effa021804cf7b7a1835826190c414036 100644 --- a/src/main/webapp/WEB-INF/jsp/pets/createOrUpdatePetForm.jsp +++ b/src/main/webapp/WEB-INF/jsp/pets/createOrUpdatePetForm.jsp @@ -1,6 +1,7 @@ <%@ taglib prefix="spring" uri="http://www.springframework.org/tags"%> <%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%> <%@ taglib prefix="form" uri="http://www.springframework.org/tags/form"%> +<%@ taglib prefix="petclinic" tagdir="/WEB-INF/tags" %> <html lang="en"> @@ -36,20 +37,8 @@ <c:out value="${pet.owner.firstName} ${pet.owner.lastName}"/> </div> - <div class="control-group"> - <label class="control-label">Name </label> - <div class="controls"> - <form:input path="name" /> - <span class="help-inline"><form:errors path="name" /></span> - </div> - </div> - <div class="control-group"> - <label class="control-label">Birth Date</label> - <div class="controls"> - <form:input path="birthDate" /> - <span class="help-inline"><form:errors path="birthDate" /></span> - </div> - </div> + <petclinic:inputField label="Name" name="name" /> + <petclinic:inputField label="Birth Date" name="birthDate" /> <div class="control-group"> <label class="control-label">Type </label> <form:select path="type" items="${types}" size="5"/> diff --git a/src/main/webapp/WEB-INF/jsp/pets/createOrUpdateVisitForm.jsp b/src/main/webapp/WEB-INF/jsp/pets/createOrUpdateVisitForm.jsp index f073b55a0ff1342a678001cf09ee396ac84f6014..80f7f0d0a464c28bb7a5a6b7a9516e0e22faa3cd 100644 --- a/src/main/webapp/WEB-INF/jsp/pets/createOrUpdateVisitForm.jsp +++ b/src/main/webapp/WEB-INF/jsp/pets/createOrUpdateVisitForm.jsp @@ -17,9 +17,8 @@ </script> <div class="container"> <jsp:include page="../fragments/bodyHeader.jsp"/> - <h2><c:if test="${visit['new']}">New </c:if>Visit:</h2> + <h2><c:if test="${visit['new']}">New </c:if>Visit</h2> - <form:form modelAttribute="visit"> <b>Pet</b> <table class="table table-striped"> <thead> @@ -38,32 +37,25 @@ </tr> </table> - <table class="table"> - <tr> - <th> - Date - <br/><form:errors path="date" cssClass="errors"/> - </th> - <td> - <form:input path="date" size="10" maxlength="10"/> - </td> - <tr/> - <tr> - <th valign="top"> - Description - <br/><form:errors path="description" cssClass="errors"/> - </th> - <td> - <form:textarea path="description" rows="10" cols="25"/> - </td> - </tr> - <tr> - <td colspan="2"> - <input type="hidden" name="petId" value="${visit.pet.id}"/> - <p class="submit"><input type="submit" value="Add Visit"/></p> - </td> - </tr> - </table> + <form:form modelAttribute="visit"> + <div class="control-group"> + <label class="control-label">Date </label> + <div class="controls"> + <form:input path="date" /> + <span class="help-inline"><form:errors path="date" /></span> + </div> + </div> + <div class="control-group"> + <label class="control-label">Description </label> + <div class="controls"> + <form:input path="description" /> + <span class="help-inline"><form:errors path="description" /></span> + </div> + </div> + <div class="form-actions"> + <input type="hidden" name="petId" value="${visit.pet.id}"/> + <button type="submit">Add Visit</button> + </div> </form:form> <br/> diff --git a/src/main/webapp/WEB-INF/tags/inputField.tag b/src/main/webapp/WEB-INF/tags/inputField.tag new file mode 100644 index 0000000000000000000000000000000000000000..f70cf36e1d9e81a70f04aa2bbbae98329d23e222 --- /dev/null +++ b/src/main/webapp/WEB-INF/tags/inputField.tag @@ -0,0 +1,16 @@ +<%@ 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"%> + +<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:input path="${name}"/> + <span class="help-inline">${status.errorMessage}</span> + </div> + </div> +</spring:bind> \ No newline at end of file