Skip to content
Snippets Groups Projects
Commit 8f531f36 authored by Mic's avatar Mic
Browse files

added custom tag

parent 07e535a7
No related branches found
No related tags found
No related merge requests found
...@@ -5,10 +5,9 @@ import javax.persistence.Entity; ...@@ -5,10 +5,9 @@ import javax.persistence.Entity;
import javax.persistence.JoinColumn; import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne; import javax.persistence.ManyToOne;
import javax.persistence.Table; import javax.persistence.Table;
import javax.validation.constraints.NotNull;
import javax.validation.constraints.Size;
import org.hibernate.annotations.Type; import org.hibernate.annotations.Type;
import org.hibernate.validator.constraints.NotEmpty;
import org.joda.time.DateTime; import org.joda.time.DateTime;
import org.springframework.format.annotation.DateTimeFormat; import org.springframework.format.annotation.DateTimeFormat;
...@@ -27,7 +26,7 @@ public class Visit extends BaseEntity { ...@@ -27,7 +26,7 @@ public class Visit extends BaseEntity {
private DateTime date; private DateTime date;
/** Holds value of property description. */ /** Holds value of property description. */
@NotNull @Size(min = 1) @NotEmpty
@Column(name="description") @Column(name="description")
private String description; private String description;
......
...@@ -3,6 +3,7 @@ ...@@ -3,6 +3,7 @@
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %> <%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions" %> <%@ taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions" %>
<%@ taglib prefix="form" uri="http://www.springframework.org/tags/form" %> <%@ taglib prefix="form" uri="http://www.springframework.org/tags/form" %>
<%@ taglib prefix="petclinic" tagdir="/WEB-INF/tags" %>
<html lang="en"> <html lang="en">
...@@ -21,68 +22,22 @@ ...@@ -21,68 +22,22 @@
<c:if test="${owner['new']}">New </c:if> Owner <c:if test="${owner['new']}">New </c:if> Owner
</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> <petclinic:inputField label="First Name" name="firstName" />
<spring:bind path="firstName"> <petclinic:inputField label="Last Name" name="lastName" />
<c:set var="cssGroup" value="control-group ${status.error ? 'error' : '' }"/> <petclinic:inputField label="Address" name="address" />
<div class="${cssGroup}" id="${firstName}"> <petclinic:inputField label="City" name="city" />
<label class="control-label">First Name</label> <petclinic:inputField label="Telephone" name="telephone" />
<div class="controls">
<form:input path="firstName"/> <div class="form-actions">
<span class="help-inline">${status.errorMessage}</span> <c:choose>
</div> <c:when test="${owner['new']}">
</div> <button type="submit">Add Owner</button>
</spring:bind> </c:when>
<spring:bind path="firstName"> <c:otherwise>
<c:set var="cssGroup" value="control-group ${status.error ? 'error' : '' }"/> <button type="submit">Update Owner</button>
<div class="${cssGroup}" id="${lastName}"> </c:otherwise>
<label class="control-label">Last Name</label> </c:choose>
<div class="controls"> </div>
<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>
</form:form> </form:form>
</div> </div>
<jsp:include page="../fragments/footer.jsp"/> <jsp:include page="../fragments/footer.jsp"/>
......
<%@ 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"%>
<%@ taglib prefix="petclinic" tagdir="/WEB-INF/tags" %>
<html lang="en"> <html lang="en">
...@@ -36,20 +37,8 @@ ...@@ -36,20 +37,8 @@
<c:out value="${pet.owner.firstName} ${pet.owner.lastName}"/> <c:out value="${pet.owner.firstName} ${pet.owner.lastName}"/>
</div> </div>
<div class="control-group"> <petclinic:inputField label="Name" name="name" />
<label class="control-label">Name </label> <petclinic:inputField label="Birth Date" name="birthDate" />
<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>
<div class="control-group"> <div class="control-group">
<label class="control-label">Type </label> <label class="control-label">Type </label>
<form:select path="type" items="${types}" size="5"/> <form:select path="type" items="${types}" size="5"/>
......
...@@ -17,9 +17,8 @@ ...@@ -17,9 +17,8 @@
</script> </script>
<div class="container"> <div class="container">
<jsp:include page="../fragments/bodyHeader.jsp"/> <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> <b>Pet</b>
<table class="table table-striped"> <table class="table table-striped">
<thead> <thead>
...@@ -38,32 +37,25 @@ ...@@ -38,32 +37,25 @@
</tr> </tr>
</table> </table>
<table class="table"> <form:form modelAttribute="visit">
<tr> <div class="control-group">
<th> <label class="control-label">Date </label>
Date <div class="controls">
<br/><form:errors path="date" cssClass="errors"/> <form:input path="date" />
</th> <span class="help-inline"><form:errors path="date" /></span>
<td> </div>
<form:input path="date" size="10" maxlength="10"/> </div>
</td> <div class="control-group">
<tr/> <label class="control-label">Description </label>
<tr> <div class="controls">
<th valign="top"> <form:input path="description" />
Description <span class="help-inline"><form:errors path="description" /></span>
<br/><form:errors path="description" cssClass="errors"/> </div>
</th> </div>
<td> <div class="form-actions">
<form:textarea path="description" rows="10" cols="25"/> <input type="hidden" name="petId" value="${visit.pet.id}"/>
</td> <button type="submit">Add Visit</button>
</tr> </div>
<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> </form:form>
<br/> <br/>
......
<%@ 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
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