diff --git a/src/main/java/org/springframework/samples/petclinic/Owner.java b/src/main/java/org/springframework/samples/petclinic/Owner.java index cb24f263e81cc628a27c48f4a891cd0f2d91ffd4..4bf7f09cea62492b838dfc91214cd674cf59fe3a 100644 --- a/src/main/java/org/springframework/samples/petclinic/Owner.java +++ b/src/main/java/org/springframework/samples/petclinic/Owner.java @@ -12,9 +12,8 @@ import javax.persistence.Entity; import javax.persistence.OneToMany; import javax.persistence.Table; import javax.validation.constraints.Digits; -import javax.validation.constraints.NotNull; -import javax.validation.constraints.Size; +import org.hibernate.validator.constraints.NotEmpty; import org.springframework.beans.support.MutableSortDefinition; import org.springframework.beans.support.PropertyComparator; import org.springframework.core.style.ToStringCreator; @@ -30,15 +29,15 @@ import org.springframework.core.style.ToStringCreator; @Entity @Table(name="owners") public class Owner extends Person { @Column(name="address") - @NotNull @Size(min = 1) + @NotEmpty private String address; @Column(name="city") - @NotNull @Size(min = 1) + @NotEmpty private String city; @Column(name="telephone") - @NotNull @Digits(fraction = 0, integer = 10) + @NotEmpty @Digits(fraction = 0, integer = 10) private String telephone; @OneToMany(cascade=CascadeType.ALL, mappedBy="owner") diff --git a/src/main/resources/log4j.xml b/src/main/resources/log4j.xml index 817cc73645c0bcf0b155497ed9ee8bbeff6ac0db..40506650ead82bfd0e467bc713c62673e339f21e 100755 --- a/src/main/resources/log4j.xml +++ b/src/main/resources/log4j.xml @@ -12,7 +12,7 @@ </appender> <logger name="org.springframework.web"> - <level value="info" /> + <level value="debug" /> </logger> <logger name="org.springframework.jdbc"> @@ -24,7 +24,7 @@ </logger> <logger name="org.hibernate.validator"> - <level value="trace" /> + <level value="debug" /> </logger> <!-- Root Logger --> diff --git a/src/main/webapp/WEB-INF/jsp/fragments/bodyHeader.jsp b/src/main/webapp/WEB-INF/jsp/fragments/bodyHeader.jsp index 71733bf6c0557636ca58ded1f0793ea78dee3bea..f360fec67ed14239c4ef5110377197abb1cbd2d3 100644 --- a/src/main/webapp/WEB-INF/jsp/fragments/bodyHeader.jsp +++ b/src/main/webapp/WEB-INF/jsp/fragments/bodyHeader.jsp @@ -8,7 +8,7 @@ <ul class="nav"> <li style="width: 100px;"><a href="<spring:url value="/" htmlEscape="true" />"><i class="icon-home"></i> Home</a></li> <li style="width: 130px;"><a href="<spring:url value="/owners/find.html" htmlEscape="true" />"><i class="icon-search"></i> Find owners</a></li> - <li style="width: 120px;"><a href="<spring:url value="/vets.html" htmlEscape="true" />"><i class="icon-th-list"></i> Veterinarians</a></li> + <li style="width: 130px;"><a href="<spring:url value="/vets.html" htmlEscape="true" />"><i class="icon-th-list"></i> Veterinarians</a></li> <li style="width: 100px;"><a href="<spring:url value="/resources/html/tutorial.html" htmlEscape="true" />"><i class=" icon-question-sign"></i> Tutorial</a></li> <li style="width: 80px;"><a href="<spring:url value="/oups.html" htmlEscape="true" />" title="trigger a RuntimeException to see how it is handled"><i class="icon-warning-sign"></i> Error</a></li> </ul> diff --git a/src/main/webapp/WEB-INF/jsp/owners/createOrUpdateOwnerForm.jsp b/src/main/webapp/WEB-INF/jsp/owners/createOrUpdateOwnerForm.jsp index 763aac06c560ae141be938850fe67460eda0321a..87025b8053347634dcdb413b78ce4eddc398a4ba 100644 --- a/src/main/webapp/WEB-INF/jsp/owners/createOrUpdateOwnerForm.jsp +++ b/src/main/webapp/WEB-INF/jsp/owners/createOrUpdateOwnerForm.jsp @@ -22,41 +22,56 @@ </h2> <form:form modelAttribute="owner" method="${method}" class="form-horizontal" id="add-owner-form"> <fieldset> - <div class="control-group" id="firstName"> - <label class="control-label">First Name </label> - <div class="controls"> - <form:input path="firstName" /> - <span class="help-inline"><form:errors path="firstName" /></span> + <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> - </div> - <div class="control-group" id="lastName"> - <label class="control-label">Last Name </label> - <div class="controls"> - <form:input path="lastName" /> - <span class="help-inline"><form:errors path="lastName" /></span> + </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> - </div> - <div class="control-group" id="address"> - <label class="control-label">Address </label> - <div class="controls"> - <form:input path="address" /> - <span class="help-inline"><form:errors path="address" /></span> + </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> - </div> - <div class="control-group" id="city"> - <label class="control-label">City </label> - <div class="controls"> - <form:input path="city" /> - <span class="help-inline"><form:errors path="city" /></span> + </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> - </div> - <div class="control-group" id="telephone"> - <label class="control-label">Telephone </label> - <div class="controls"> - <form:input path="telephone" /> - <span class="help-inline"><form:errors path="telephone" /></span> + </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> - </div> + </spring:bind> <div class="form-actions"> <c:choose> <c:when test="${owner['new']}"> diff --git a/src/main/webapp/WEB-INF/jsp/pets/createOrUpdatePetForm.jsp b/src/main/webapp/WEB-INF/jsp/pets/createOrUpdatePetForm.jsp index 3ee7caeca6dd7f0638c6ac0648774655d21fbda3..b118a6fc37cdd2f56186d3382cecfa1ceeef5cb9 100644 --- a/src/main/webapp/WEB-INF/jsp/pets/createOrUpdatePetForm.jsp +++ b/src/main/webapp/WEB-INF/jsp/pets/createOrUpdatePetForm.jsp @@ -1,43 +1,74 @@ -<%@ 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="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"%> <html lang="en"> - +<jsp:include page="../fragments/headTag.jsp"/> <body> - <head> - <spring:url value="/webjars/jquery/1.8.2/jquery.js" var="jQuery" /> - <script src="${jQuery}"></script> - - <spring:url value="/webjars/jquery-ui/1.9.1/js/jquery-ui-1.9.1.custom.js" var="jQueryUi" /> - <script src="${jQueryUi}"></script> - - <spring:url value="/webjars/jquery-ui/1.9.1/css/smoothness/jquery-ui-1.9.1.custom.css" var="jQueryUiCss" /> - <link href="${jQueryUiCss}" rel="stylesheet"></link> - - - </head> - <div class="container"> - + <script> - $(function() { - $( "#birthDate" ).datepicker(); - }); - </script> - <form:form modelAttribute="pet" class="form-horizontal"> - <fieldset> - <div class="control-group" id="birthDate"> - <label class="control-label">Birth Date</label> - <div class="controls"> - <form:input path="birthDate" /> - </div> - </div> + $(function() { + $("#birthDate").datepicker(); + }); +</script> + <div class="container"> + <jsp:include page="../fragments/bodyHeader.jsp" /> + <c:choose> + <c:when test="${pet['new']}"> + <c:set var="method" value="post" /> + </c:when> + <c:otherwise> + <c:set var="method" value="put" /> + </c:otherwise> + </c:choose> + + <h2> + <c:if test="${pet['new']}">New </c:if> + Pet + </h2> + + <form:form modelAttribute="pet" method="${method}" + class="form-horizontal"> + <div class="control-group" id="owner"> + <label class="control-label">Owner </label> - </fieldset> - </form:form> - </div> + <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 (yyyy-MM-dd)</label> + <div class="controls"> + <form:input path="birthDate" /> + <span class="help-inline"><form:errors path="birthDate" /></span> + </div> + </div> + <div class="control-group"> + <label class="control-label">Type </label> + <form:select path="type" items="${types}" size="5"/> + </div> + <div class="form-actions"> + <c:choose> + <c:when test="${pet['new']}"> + <button type="submit">Add Pet</button> + </c:when> + <c:otherwise> + <button type="submit">Update Pet</button> + </c:otherwise> + </c:choose> + </div> + </form:form> + <c:if test="${!pet['new']}"> + </c:if> + <jsp:include page="../fragments/footer.jsp" /> + </div> </body> </html> diff --git a/src/main/webapp/resources/css/petclinic.css b/src/main/webapp/resources/css/petclinic.css index 8e31eaedf6b7c59bbf4fd37e16485e2c4805db3a..590cbe06ea239339c47a7add54078ce4541245c5 100644 --- a/src/main/webapp/resources/css/petclinic.css +++ b/src/main/webapp/resources/css/petclinic.css @@ -15,3 +15,7 @@ input[type="text"] { .navbar .nav > li > a { color: #000000; } + + .form-horizontal .control-label { + text-align: left; +}