Skip to content

Commit

Permalink
Simplify jsp layout management
Browse files Browse the repository at this point in the history
abstract the page layout into “layout.tag”
  • Loading branch information
verydapeng authored and arey committed Jun 27, 2016
1 parent 50f46fd commit a2849f7
Show file tree
Hide file tree
Showing 14 changed files with 287 additions and 410 deletions.
34 changes: 7 additions & 27 deletions src/main/webapp/WEB-INF/jsp/exception.jsp
Original file line number Diff line number Diff line change
@@ -1,34 +1,14 @@
<!DOCTYPE html>

<%@ page session="false" %>
<%@ page session="false" trimDirectiveWhitespaces="true" %>
<%@ taglib prefix="spring" uri="http://www.springframework.org/tags" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix="petclinic" tagdir="/WEB-INF/tags" %>

<html lang="en">
<jsp:include page="fragments/htmlHeader.jsp"/>

<body>
<petclinic:bodyHeader menuName="error"/>
<div class="container-fluid">
<div class="container xd-container">

<spring:url value="/resources/images/pets.png" var="petsImage"/>
<img src="${petsImage}"/>
<petclinic:layout pageName="error">

<h2>Something happened...</h2>
<spring:url value="/resources/images/pets.png" var="petsImage"/>
<img src="${petsImage}"/>

<p>${exception.message}</p>
<h2>Something happened...</h2>

<!-- Exception: ${exception.message}.
<c:forEach items="${exception.stackTrace}" var="stackTrace">
${stackTrace}
</c:forEach>
-->
<petclinic:pivotal/>
</div>
</div>
<jsp:include page="fragments/footer.jsp"/>
</body>
<p>${exception.message}</p>

</html>
</petclinic:layout>
66 changes: 25 additions & 41 deletions src/main/webapp/WEB-INF/jsp/owners/createOrUpdateOwnerForm.jsp
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
<!DOCTYPE html>

<%@ page session="false" %>
<%@ taglib prefix="spring" uri="http://www.springframework.org/tags" %>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>
Expand All @@ -8,43 +6,29 @@
<%@ taglib prefix="form" uri="http://www.springframework.org/tags/form" %>
<%@ taglib prefix="petclinic" tagdir="/WEB-INF/tags" %>


<html lang="en">

<jsp:include page="../fragments/htmlHeader.jsp"/>

<body>
<petclinic:bodyHeader menuName="owners"/>
<div class="container-fluid">
<div class="container xd-container">
<h2>
<c:if test="${owner['new']}">New </c:if> Owner
</h2>
<form:form modelAttribute="owner" class="form-horizontal" id="add-owner-form">
<div class="form-group has-feedback">
<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>
<div class="form-group">
<div class="col-sm-offset-2 col-sm-10">
<c:choose>
<c:when test="${owner['new']}">
<button class="btn btn-default" type="submit">Add Owner</button>
</c:when>
<c:otherwise>
<button class="btn btn-default" type="submit">Update Owner</button>
</c:otherwise>
</c:choose>
</div>
<petclinic:layout pageName="owners">
<h2>
<c:if test="${owner['new']}">New </c:if> Owner
</h2>
<form:form modelAttribute="owner" class="form-horizontal" id="add-owner-form">
<div class="form-group has-feedback">
<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>
<div class="form-group">
<div class="col-sm-offset-2 col-sm-10">
<c:choose>
<c:when test="${owner['new']}">
<button class="btn btn-default" type="submit">Add Owner</button>
</c:when>
<c:otherwise>
<button class="btn btn-default" type="submit">Update Owner</button>
</c:otherwise>
</c:choose>
</div>
</form:form>
<petclinic:pivotal/>
</div>
</div>
<jsp:include page="../fragments/footer.jsp"/>
</body>

</html>
</div>
</form:form>
</petclinic:layout>
57 changes: 20 additions & 37 deletions src/main/webapp/WEB-INF/jsp/owners/findOwners.jsp
Original file line number Diff line number Diff line change
@@ -1,51 +1,34 @@
<!DOCTYPE html>

<%@ page session="false" %>
<%@ taglib prefix="spring" uri="http://www.springframework.org/tags" %>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>
<%@ taglib prefix="form" uri="http://www.springframework.org/tags/form" %>
<%@ taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions" %>
<%@ taglib prefix="petclinic" tagdir="/WEB-INF/tags" %>

<html lang="en">

<jsp:include page="../fragments/htmlHeader.jsp"/>
<petclinic:layout pageName="owners">

<body>
<petclinic:bodyHeader menuName="owners"/>
<div class="container-fluid">
<div class="container xd-container">
<h2>Find Owners</h2>

<h2>Find Owners</h2>

<spring:url value="/owners.html" var="formUrl"/>
<form:form modelAttribute="owner" action="${fn:escapeXml(formUrl)}" method="get" class="form-horizontal"
id="search-owner-form">
<div class="form-group">
<div class="control-group" id="lastName">
<label class="col-sm-2 control-label">Last name </label>
<div class="col-sm-10">
<form:input class="form-control" path="lastName" size="30" maxlength="80"/>
<span class="help-inline"><form:errors path="*"/></span>
</div>
<spring:url value="/owners.html" var="formUrl"/>
<form:form modelAttribute="owner" action="${fn:escapeXml(formUrl)}" method="get" class="form-horizontal"
id="search-owner-form">
<div class="form-group">
<div class="control-group" id="lastName">
<label class="col-sm-2 control-label">Last name </label>
<div class="col-sm-10">
<form:input class="form-control" path="lastName" size="30" maxlength="80"/>
<span class="help-inline"><form:errors path="*"/></span>
</div>
</div>
<div class="form-group">
<div class="col-sm-offset-2 col-sm-10">
<button type="submit" class="btn btn-default">Find Owner</button>
</div>
</div>
<div class="form-group">
<div class="col-sm-offset-2 col-sm-10">
<button type="submit" class="btn btn-default">Find Owner</button>
</div>
</div>

</form:form>

<br/>
<a class="btn btn-default" href='<spring:url value="/owners/new" htmlEscape="true"/>'>Add Owner</a>

<petclinic:pivotal/>
</div>
</div>

<jsp:include page="../fragments/footer.jsp"/>
</body>
</form:form>

</html>
<br/>
<a class="btn btn-default" href='<spring:url value="/owners/new" htmlEscape="true"/>'>Add Owner</a>
</petclinic:layout>
187 changes: 85 additions & 102 deletions src/main/webapp/WEB-INF/jsp/owners/ownerDetails.jsp
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
<!DOCTYPE html>

<%@ page session="false" %>
<%@ taglib prefix="spring" uri="http://www.springframework.org/tags" %>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>
Expand All @@ -8,109 +6,94 @@
<%@ taglib prefix="joda" uri="http://www.joda.org/joda/time/tags" %>
<%@ taglib prefix="petclinic" tagdir="/WEB-INF/tags" %>

<html lang="en">

<jsp:include page="../fragments/htmlHeader.jsp"/>

<body>
<petclinic:bodyHeader menuName="owners"/>
<div class="container-fluid">
<div class="container xd-container">
<petclinic:layout pageName="owners">

<h2>Owner Information</h2>


<table class="table table-striped">
<tr>
<th>Name</th>
<td><b><c:out value="${owner.firstName} ${owner.lastName}"/></b></td>
</tr>
<tr>
<th>Address</th>
<td><c:out value="${owner.address}"/></td>
</tr>
<tr>
<th>City</th>
<td><c:out value="${owner.city}"/></td>
</tr>
<tr>
<th>Telephone</th>
<td><c:out value="${owner.telephone}"/></td>
</tr>
</table>

<spring:url value="{ownerId}/edit.html" var="editUrl">
<spring:param name="ownerId" value="${owner.id}"/>
</spring:url>
<a href="${fn:escapeXml(editUrl)}" class="btn btn-default">Edit Owner</a>

<spring:url value="{ownerId}/pets/new.html" var="addUrl">
<spring:param name="ownerId" value="${owner.id}"/>
</spring:url>
<a href="${fn:escapeXml(addUrl)}" class="btn btn-default">Add New Pet</a>

<br/>
<br/>
<br/>
<h2>Pets and Visits</h2>

<table class="table table-striped">
<c:forEach var="pet" items="${owner.pets}">

<h2>Owner Information</h2>


<table class="table table-striped">
<tr>
<th>Name</th>
<td><b><c:out value="${owner.firstName} ${owner.lastName}"/></b></td>
</tr>
<tr>
<th>Address</th>
<td><c:out value="${owner.address}"/></td>
</tr>
<tr>
<th>City</th>
<td><c:out value="${owner.city}"/></td>
</tr>
<tr>
<th>Telephone</th>
<td><c:out value="${owner.telephone}"/></td>
</tr>
</table>

<spring:url value="{ownerId}/edit.html" var="editUrl">
<spring:param name="ownerId" value="${owner.id}"/>
</spring:url>
<a href="${fn:escapeXml(editUrl)}" class="btn btn-default">Edit Owner</a>

<spring:url value="{ownerId}/pets/new.html" var="addUrl">
<spring:param name="ownerId" value="${owner.id}"/>
</spring:url>
<a href="${fn:escapeXml(addUrl)}" class="btn btn-default">Add New Pet</a>

<br/>
<br/>
<br/>
<h2>Pets and Visits</h2>

<table class="table table-striped">
<c:forEach var="pet" items="${owner.pets}">

<tr>
<td valign="top">
<dl class="dl-horizontal">
<dt>Name</dt>
<dd><c:out value="${pet.name}"/></dd>
<dt>Birth Date</dt>
<dd><joda:format value="${pet.birthDate}" pattern="yyyy-MM-dd"/></dd>
<dt>Type</dt>
<dd><c:out value="${pet.type.name}"/></dd>
</dl>
</td>
<td valign="top">
<table class="table-condensed">
<thead>
<td valign="top">
<dl class="dl-horizontal">
<dt>Name</dt>
<dd><c:out value="${pet.name}"/></dd>
<dt>Birth Date</dt>
<dd><joda:format value="${pet.birthDate}" pattern="yyyy-MM-dd"/></dd>
<dt>Type</dt>
<dd><c:out value="${pet.type.name}"/></dd>
</dl>
</td>
<td valign="top">
<table class="table-condensed">
<thead>
<tr>
<th>Visit Date</th>
<th>Description</th>
</tr>
</thead>
<c:forEach var="visit" items="${pet.visits}">
<tr>
<th>Visit Date</th>
<th>Description</th>
<td><joda:format value="${visit.date}" pattern="yyyy-MM-dd"/></td>
<td><c:out value="${visit.description}"/></td>
</tr>
</thead>
<c:forEach var="visit" items="${pet.visits}">
<tr>
<td><joda:format value="${visit.date}" pattern="yyyy-MM-dd"/></td>
<td><c:out value="${visit.description}"/></td>
</tr>
</c:forEach>
<tr>
<td>
<spring:url value="/owners/{ownerId}/pets/{petId}/edit" var="petUrl">
<spring:param name="ownerId" value="${owner.id}"/>
<spring:param name="petId" value="${pet.id}"/>
</spring:url>
<a href="${fn:escapeXml(petUrl)}">Edit Pet</a>
</td>
<td>
<spring:url value="/owners/{ownerId}/pets/{petId}/visits/new" var="visitUrl">
<spring:param name="ownerId" value="${owner.id}"/>
<spring:param name="petId" value="${pet.id}"/>
</spring:url>
<a href="${fn:escapeXml(visitUrl)}">Add Visit</a>
</td>
</tr>
</table>
</td>
</tr>

</c:forEach>
</table>

<petclinic:pivotal/>
</div>
</div>

<jsp:include page="../fragments/footer.jsp"/>
</c:forEach>
<tr>
<td>
<spring:url value="/owners/{ownerId}/pets/{petId}/edit" var="petUrl">
<spring:param name="ownerId" value="${owner.id}"/>
<spring:param name="petId" value="${pet.id}"/>
</spring:url>
<a href="${fn:escapeXml(petUrl)}">Edit Pet</a>
</td>
<td>
<spring:url value="/owners/{ownerId}/pets/{petId}/visits/new" var="visitUrl">
<spring:param name="ownerId" value="${owner.id}"/>
<spring:param name="petId" value="${pet.id}"/>
</spring:url>
<a href="${fn:escapeXml(visitUrl)}">Add Visit</a>
</td>
</tr>
</table>
</td>
</tr>

</body>
</c:forEach>
</table>

</html>
</petclinic:layout>
Loading

0 comments on commit a2849f7

Please sign in to comment.