Skip to content
Snippets Groups Projects
Commit 6eae6971 authored by Mic's avatar Mic
Browse files

improved pet creation form

parent ab5a3e29
No related branches found
No related tags found
No related merge requests found
...@@ -12,9 +12,8 @@ import javax.persistence.Entity; ...@@ -12,9 +12,8 @@ import javax.persistence.Entity;
import javax.persistence.OneToMany; import javax.persistence.OneToMany;
import javax.persistence.Table; import javax.persistence.Table;
import javax.validation.constraints.Digits; 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.MutableSortDefinition;
import org.springframework.beans.support.PropertyComparator; import org.springframework.beans.support.PropertyComparator;
import org.springframework.core.style.ToStringCreator; import org.springframework.core.style.ToStringCreator;
...@@ -30,15 +29,15 @@ import org.springframework.core.style.ToStringCreator; ...@@ -30,15 +29,15 @@ import org.springframework.core.style.ToStringCreator;
@Entity @Table(name="owners") @Entity @Table(name="owners")
public class Owner extends Person { public class Owner extends Person {
@Column(name="address") @Column(name="address")
@NotNull @Size(min = 1) @NotEmpty
private String address; private String address;
@Column(name="city") @Column(name="city")
@NotNull @Size(min = 1) @NotEmpty
private String city; private String city;
@Column(name="telephone") @Column(name="telephone")
@NotNull @Digits(fraction = 0, integer = 10) @NotEmpty @Digits(fraction = 0, integer = 10)
private String telephone; private String telephone;
@OneToMany(cascade=CascadeType.ALL, mappedBy="owner") @OneToMany(cascade=CascadeType.ALL, mappedBy="owner")
......
...@@ -12,7 +12,7 @@ ...@@ -12,7 +12,7 @@
</appender> </appender>
<logger name="org.springframework.web"> <logger name="org.springframework.web">
<level value="info" /> <level value="debug" />
</logger> </logger>
<logger name="org.springframework.jdbc"> <logger name="org.springframework.jdbc">
...@@ -24,7 +24,7 @@ ...@@ -24,7 +24,7 @@
</logger> </logger>
<logger name="org.hibernate.validator"> <logger name="org.hibernate.validator">
<level value="trace" /> <level value="debug" />
</logger> </logger>
<!-- Root Logger --> <!-- Root Logger -->
......
...@@ -8,7 +8,7 @@ ...@@ -8,7 +8,7 @@
<ul class="nav"> <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: 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: 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: 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> <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> </ul>
......
...@@ -22,41 +22,56 @@ ...@@ -22,41 +22,56 @@
</h2> </h2>
<form:form modelAttribute="owner" method="${method}" class="form-horizontal" id="add-owner-form"> <form:form modelAttribute="owner" method="${method}" class="form-horizontal" id="add-owner-form">
<fieldset> <fieldset>
<div class="control-group" id="firstName"> <spring:bind path="firstName">
<label class="control-label">First Name </label> <c:set var="cssGroup" value="control-group ${status.error ? 'error' : '' }"/>
<div class="controls"> <div class="${cssGroup}" id="${firstName}">
<form:input path="firstName" /> <label class="control-label">First Name</label>
<span class="help-inline"><form:errors path="firstName" /></span> <div class="controls">
<form:input path="firstName"/>
<span class="help-inline">${status.errorMessage}</span>
</div>
</div> </div>
</div> </spring:bind>
<div class="control-group" id="lastName"> <spring:bind path="firstName">
<label class="control-label">Last Name </label> <c:set var="cssGroup" value="control-group ${status.error ? 'error' : '' }"/>
<div class="controls"> <div class="${cssGroup}" id="${lastName}">
<form:input path="lastName" /> <label class="control-label">Last Name</label>
<span class="help-inline"><form:errors path="lastName" /></span> <div class="controls">
<form:input path="lastName"/>
<span class="help-inline">${status.errorMessage}</span>
</div>
</div> </div>
</div> </spring:bind>
<div class="control-group" id="address"> <spring:bind path="address">
<label class="control-label">Address </label> <c:set var="cssGroup" value="control-group ${status.error ? 'error' : '' }"/>
<div class="controls"> <div class="${cssGroup}" id="${address}">
<form:input path="address" /> <label class="control-label">Address</label>
<span class="help-inline"><form:errors path="address" /></span> <div class="controls">
<form:input path="address"/>
<span class="help-inline">${status.errorMessage}</span>
</div>
</div> </div>
</div> </spring:bind>
<div class="control-group" id="city"> <spring:bind path="city">
<label class="control-label">City </label> <c:set var="cssGroup" value="control-group ${status.error ? 'error' : '' }"/>
<div class="controls"> <div class="${cssGroup}" id="${city}">
<form:input path="city" /> <label class="control-label">City</label>
<span class="help-inline"><form:errors path="city" /></span> <div class="controls">
<form:input path="city"/>
<span class="help-inline">${status.errorMessage}</span>
</div>
</div> </div>
</div> </spring:bind>
<div class="control-group" id="telephone"> <spring:bind path="telephone">
<label class="control-label">Telephone </label> <c:set var="cssGroup" value="control-group ${status.error ? 'error' : '' }"/>
<div class="controls"> <div class="${cssGroup}" id="${telephone}">
<form:input path="telephone" /> <label class="control-label">Telephone</label>
<span class="help-inline"><form:errors path="telephone" /></span> <div class="controls">
<form:input path="telephone"/>
<span class="help-inline">${status.errorMessage}</span>
</div>
</div> </div>
</div> </spring:bind>
<div class="form-actions"> <div class="form-actions">
<c:choose> <c:choose>
<c:when test="${owner['new']}"> <c:when test="${owner['new']}">
......
<%@ taglib prefix="spring" uri="http://www.springframework.org/tags" %> <%@ taglib prefix="spring" uri="http://www.springframework.org/tags"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %> <%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@ taglib prefix="form" uri="http://www.springframework.org/tags/form" %> <%@ taglib prefix="form" uri="http://www.springframework.org/tags/form"%>
<html lang="en"> <html lang="en">
<jsp:include page="../fragments/headTag.jsp"/>
<body> <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> <script>
$(function() { $(function() {
$( "#birthDate" ).datepicker(); $("#birthDate").datepicker();
}); });
</script> </script>
<form:form modelAttribute="pet" class="form-horizontal"> <div class="container">
<fieldset> <jsp:include page="../fragments/bodyHeader.jsp" />
<div class="control-group" id="birthDate"> <c:choose>
<label class="control-label">Birth Date</label> <c:when test="${pet['new']}">
<div class="controls"> <c:set var="method" value="post" />
<form:input path="birthDate" /> </c:when>
</div> <c:otherwise>
</div> <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> <c:out value="${pet.owner.firstName} ${pet.owner.lastName}"/>
</form:form> </div>
</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> </body>
</html> </html>
...@@ -15,3 +15,7 @@ input[type="text"] { ...@@ -15,3 +15,7 @@ input[type="text"] {
.navbar .nav > li > a { .navbar .nav > li > a {
color: #000000; color: #000000;
} }
.form-horizontal .control-label {
text-align: left;
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment