mirror of
https://github.com/spring-projects/spring-petclinic.git
synced 2025-07-15 12:15:50 +00:00
added custom tag
This commit is contained in:
parent
07e535a75e
commit
8f531f366f
5 changed files with 58 additions and 107 deletions
|
@ -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;
|
||||
|
||||
|
|
|
@ -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"/>
|
||||
|
|
|
@ -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"/>
|
||||
|
|
|
@ -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/>
|
||||
|
|
16
src/main/webapp/WEB-INF/tags/inputField.tag
Normal file
16
src/main/webapp/WEB-INF/tags/inputField.tag
Normal file
|
@ -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>
|
Loading…
Reference in a new issue