mirror of
https://github.com/spring-projects/spring-petclinic.git
synced 2025-05-29 06:39:38 +00:00
simplify jsp layout management
abstract the page layout into “layout.tag”
This commit is contained in:
parent
beb46b2b3b
commit
aa8cc431eb
12 changed files with 281 additions and 404 deletions
|
@ -1,17 +1,8 @@
|
|||
<!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">
|
||||
<petclinic:htmlHeader />
|
||||
|
||||
<body>
|
||||
<petclinic:bodyHeader menuName="error"/>
|
||||
<div class="container-fluid">
|
||||
<div class="container xd-container">
|
||||
<petclinic:layout pageName="error">
|
||||
|
||||
<spring:url value="/resources/images/pets.png" var="petsImage"/>
|
||||
<img src="${petsImage}"/>
|
||||
|
@ -20,15 +11,4 @@
|
|||
|
||||
<p>${exception.message}</p>
|
||||
|
||||
<!-- Exception: ${exception.message}.
|
||||
<c:forEach items="${exception.stackTrace}" var="stackTrace">
|
||||
${stackTrace}
|
||||
</c:forEach>
|
||||
-->
|
||||
<petclinic:pivotal/>
|
||||
</div>
|
||||
</div>
|
||||
<petclinic:footer/>
|
||||
</body>
|
||||
|
||||
</html>
|
||||
</petclinic:layout>
|
||||
|
|
|
@ -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" %>
|
||||
|
@ -8,15 +6,7 @@
|
|||
<%@ taglib prefix="form" uri="http://www.springframework.org/tags/form" %>
|
||||
<%@ taglib prefix="petclinic" tagdir="/WEB-INF/tags" %>
|
||||
|
||||
|
||||
<html lang="en">
|
||||
|
||||
<petclinic:htmlHeader />
|
||||
|
||||
<body>
|
||||
<petclinic:bodyHeader menuName="owners"/>
|
||||
<div class="container-fluid">
|
||||
<div class="container xd-container">
|
||||
<petclinic:layout pageName="owners">
|
||||
<h2>
|
||||
<c:if test="${owner['new']}">New </c:if> Owner
|
||||
</h2>
|
||||
|
@ -41,10 +31,4 @@
|
|||
</div>
|
||||
</div>
|
||||
</form:form>
|
||||
<petclinic:pivotal/>
|
||||
</div>
|
||||
</div>
|
||||
<petclinic:footer />
|
||||
</body>
|
||||
|
||||
</html>
|
||||
</petclinic:layout>
|
||||
|
|
|
@ -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" %>
|
||||
|
@ -7,14 +5,7 @@
|
|||
<%@ taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions" %>
|
||||
<%@ taglib prefix="petclinic" tagdir="/WEB-INF/tags" %>
|
||||
|
||||
<html lang="en">
|
||||
|
||||
<petclinic:htmlHeader />
|
||||
|
||||
<body>
|
||||
<petclinic:bodyHeader menuName="owners"/>
|
||||
<div class="container-fluid">
|
||||
<div class="container xd-container">
|
||||
<petclinic:layout pageName="owners">
|
||||
|
||||
<h2>Find Owners</h2>
|
||||
|
||||
|
@ -40,12 +31,4 @@
|
|||
|
||||
<br/>
|
||||
<a class="btn btn-default" href='<spring:url value="/owners/new" htmlEscape="true"/>'>Add Owner</a>
|
||||
|
||||
<petclinic:pivotal/>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<petclinic:footer />
|
||||
</body>
|
||||
|
||||
</html>
|
||||
</petclinic:layout>
|
||||
|
|
|
@ -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" %>
|
||||
|
@ -8,14 +6,7 @@
|
|||
<%@ taglib prefix="joda" uri="http://www.joda.org/joda/time/tags" %>
|
||||
<%@ taglib prefix="petclinic" tagdir="/WEB-INF/tags" %>
|
||||
|
||||
<html lang="en">
|
||||
|
||||
<petclinic:htmlHeader />
|
||||
|
||||
<body>
|
||||
<petclinic:bodyHeader menuName="owners"/>
|
||||
<div class="container-fluid">
|
||||
<div class="container xd-container">
|
||||
<petclinic:layout pageName="owners">
|
||||
|
||||
<h2>Owner Information</h2>
|
||||
|
||||
|
@ -105,12 +96,4 @@
|
|||
</c:forEach>
|
||||
</table>
|
||||
|
||||
<petclinic:pivotal/>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<petclinic:footer />
|
||||
|
||||
</body>
|
||||
|
||||
</html>
|
||||
</petclinic:layout>
|
||||
|
|
|
@ -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" %>
|
||||
|
@ -8,14 +6,7 @@
|
|||
<%@ taglib prefix="datatables" uri="http://github.com/dandelion/datatables" %>
|
||||
<%@ taglib prefix="petclinic" tagdir="/WEB-INF/tags" %>
|
||||
|
||||
<html lang="en">
|
||||
|
||||
<petclinic:htmlHeader />
|
||||
|
||||
<body>
|
||||
<petclinic:bodyHeader menuName="owners"/>
|
||||
<div class="container-fluid">
|
||||
<div class="container xd-container">
|
||||
<petclinic:layout pageName="owners">
|
||||
<h2>Owners</h2>
|
||||
|
||||
<datatables:table id="owners" data="${selections}" row="owner"
|
||||
|
@ -39,12 +30,4 @@
|
|||
</datatables:column>
|
||||
<datatables:export type="pdf" cssClass="btn" cssStyle="height: 25px;"/>
|
||||
</datatables:table>
|
||||
|
||||
<petclinic:pivotal/>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<petclinic:footer />
|
||||
</body>
|
||||
|
||||
</html>
|
||||
</petclinic:layout>
|
||||
|
|
|
@ -1,20 +1,18 @@
|
|||
<!DOCTYPE html>
|
||||
|
||||
<%@ page session="false" %>
|
||||
<%@ 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">
|
||||
|
||||
<petclinic:htmlHeader />
|
||||
<body>
|
||||
<petclinic:bodyHeader menuName="owners"/>
|
||||
|
||||
<div class="container-fluid">
|
||||
<div class="container xd-container">
|
||||
<petclinic:layout pageName="owners">
|
||||
<jsp:attribute name="customScript">
|
||||
<script>
|
||||
$(function () {
|
||||
$("#birthDate").datepicker({dateFormat: 'yy/mm/dd'});
|
||||
});
|
||||
</script>
|
||||
</jsp:attribute>
|
||||
<jsp:body>
|
||||
<h2>
|
||||
<c:if test="${pet['new']}">New </c:if> Pet
|
||||
</h2>
|
||||
|
@ -49,17 +47,5 @@
|
|||
</form:form>
|
||||
<c:if test="${!pet['new']}">
|
||||
</c:if>
|
||||
|
||||
<petclinic:pivotal/>
|
||||
</div>
|
||||
</div>
|
||||
<petclinic:footer />
|
||||
|
||||
<script>
|
||||
$(function () {
|
||||
$("#birthDate").datepicker({dateFormat: 'yy/mm/dd'});
|
||||
});
|
||||
</script>
|
||||
</body>
|
||||
|
||||
</html>
|
||||
</jsp:body>
|
||||
</petclinic:layout>
|
||||
|
|
|
@ -1,6 +1,4 @@
|
|||
<!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="form" uri="http://www.springframework.org/tags/form" %>
|
||||
|
@ -9,15 +7,15 @@
|
|||
<%@ taglib prefix="petclinic" tagdir="/WEB-INF/tags" %>
|
||||
|
||||
|
||||
<html lang="en">
|
||||
|
||||
<petclinic:htmlHeader />
|
||||
|
||||
<body>
|
||||
|
||||
<petclinic:bodyHeader menuName="owners"/>
|
||||
<div class="container-fluid">
|
||||
<div class="container xd-container">
|
||||
<petclinic:layout pageName="owners">
|
||||
<jsp:attribute name="customScript">
|
||||
<script>
|
||||
$(function () {
|
||||
$("#date").datepicker({dateFormat: 'yy/mm/dd'});
|
||||
});
|
||||
</script>
|
||||
</jsp:attribute>
|
||||
<jsp:body>
|
||||
<h2><c:if test="${visit['new']}">New </c:if>Visit</h2>
|
||||
|
||||
<b>Pet</b>
|
||||
|
@ -68,16 +66,6 @@
|
|||
</c:if>
|
||||
</c:forEach>
|
||||
</table>
|
||||
</jsp:body>
|
||||
|
||||
<petclinic:pivotal/>
|
||||
</div>
|
||||
</div>
|
||||
<petclinic:footer />
|
||||
<script>
|
||||
$(function () {
|
||||
$("#date").datepicker({dateFormat: 'yy/mm/dd'});
|
||||
});
|
||||
</script>
|
||||
</body>
|
||||
|
||||
</html>
|
||||
</petclinic:layout>
|
||||
|
|
|
@ -1,20 +1,11 @@
|
|||
<!DOCTYPE html>
|
||||
|
||||
<%@ page session="false" %>
|
||||
<%@ page session="false" trimDirectiveWhitespaces="true" %>
|
||||
<%@ taglib prefix="spring" uri="http://www.springframework.org/tags" %>
|
||||
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>
|
||||
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
|
||||
<%@ taglib prefix="datatables" uri="http://github.com/dandelion/datatables" %>
|
||||
<%@ taglib prefix="petclinic" tagdir="/WEB-INF/tags" %>
|
||||
|
||||
<html lang="en">
|
||||
|
||||
<petclinic:htmlHeader />
|
||||
|
||||
<body>
|
||||
<petclinic:bodyHeader menuName="vets"/>
|
||||
<div class="container-fluid">
|
||||
<div class="container xd-container">
|
||||
<petclinic:layout pageName="vets">
|
||||
<h2>Veterinarians</h2>
|
||||
|
||||
<datatables:table id="vets" data="${vets.vetList}" row="vet" cssClass="table table-striped"
|
||||
|
@ -40,11 +31,4 @@
|
|||
</td>
|
||||
</tr>
|
||||
</table>
|
||||
|
||||
<petclinic:pivotal/>
|
||||
</div>
|
||||
</div>
|
||||
<petclinic:footer />
|
||||
</body>
|
||||
|
||||
</html>
|
||||
</petclinic:layout>
|
||||
|
|
|
@ -1,20 +1,9 @@
|
|||
<!DOCTYPE html>
|
||||
|
||||
<%@ page session="false" %>
|
||||
<%@ page session="false" trimDirectiveWhitespaces="true" %>
|
||||
<%@ taglib prefix="spring" uri="http://www.springframework.org/tags" %>
|
||||
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>
|
||||
<%@ taglib prefix="petclinic" tagdir="/WEB-INF/tags" %>
|
||||
|
||||
|
||||
<html lang="en">
|
||||
|
||||
<petclinic:htmlHeader/>
|
||||
|
||||
<body>
|
||||
<petclinic:bodyHeader menuName="home"/>
|
||||
|
||||
<div class="container-fluid">
|
||||
<div class="container xd-container">
|
||||
<petclinic:layout pageName="home">
|
||||
<h2><fmt:message key="welcome"/></h2>
|
||||
<div class="row">
|
||||
<div class="col-md-12">
|
||||
|
@ -22,11 +11,4 @@
|
|||
<img class="img-responsive" src="${petsImage}"/>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<petclinic:pivotal/>
|
||||
</div>
|
||||
</div>
|
||||
<petclinic:footer/>
|
||||
</body>
|
||||
|
||||
</html>
|
||||
</petclinic:layout>
|
||||
|
|
27
src/main/webapp/WEB-INF/tags/layout.tag
Normal file
27
src/main/webapp/WEB-INF/tags/layout.tag
Normal file
|
@ -0,0 +1,27 @@
|
|||
<%@ tag trimDirectiveWhitespaces="true" %>
|
||||
<%@ taglib prefix="petclinic" tagdir="/WEB-INF/tags" %>
|
||||
|
||||
<%@ attribute name="pageName" required="true" %>
|
||||
<%@ attribute name="customScript" required="false" fragment="true"%>
|
||||
|
||||
<!doctype html>
|
||||
<html>
|
||||
<petclinic:htmlHeader/>
|
||||
|
||||
<body>
|
||||
<petclinic:bodyHeader menuName="${pageName}"/>
|
||||
|
||||
<div class="container-fluid">
|
||||
<div class="container xd-container">
|
||||
|
||||
<jsp:doBody/>
|
||||
|
||||
<petclinic:pivotal/>
|
||||
</div>
|
||||
</div>
|
||||
<petclinic:footer/>
|
||||
<jsp:invoke fragment="customScript" />
|
||||
|
||||
</body>
|
||||
|
||||
</html>
|
|
@ -1,10 +1,9 @@
|
|||
<%@ 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" %>
|
||||
<%@ attribute name="name" required="true" rtexprvalue="true"
|
||||
description="Name of the active menu: home, owners, vets or error" %>
|
||||
|
||||
<%-- Static navbar --%>
|
||||
<nav class="navbar navbar-default" role="navigation">
|
||||
<div class="container">
|
||||
<div class="navbar-header">
|
||||
|
@ -18,44 +17,29 @@
|
|||
</div>
|
||||
<div class="navbar-collapse collapse">
|
||||
<ul class="nav navbar-nav navbar-right">
|
||||
<c:choose>
|
||||
<c:when test="${name eq 'home'}">
|
||||
<c:set var="cssMenu" value="active"/>
|
||||
</c:when>
|
||||
<c:otherwise>
|
||||
<c:set var="cssMenu" value=""/>
|
||||
</c:otherwise>
|
||||
</c:choose>
|
||||
<li class="${cssMenu}"><a href="<spring:url value="/" htmlEscape="true" />"><span class="glyphicon glyphicon-home" aria-hidden="true"></span><span> Home</span></a></li>
|
||||
<c:choose>
|
||||
<c:when test="${name eq 'owners'}">
|
||||
<c:set var="cssMenu" value="active"/>
|
||||
</c:when>
|
||||
<c:otherwise>
|
||||
<c:set var="cssMenu" value=""/>
|
||||
</c:otherwise>
|
||||
</c:choose>
|
||||
<li class="${cssMenu}"><a href="<spring:url value="/owners/find.html" htmlEscape="true" />"><span class="glyphicon glyphicon-search" aria-hidden="true"></span><span> Find owners</span></a></li>
|
||||
<c:choose>
|
||||
<c:when test="${name eq 'vets'}">
|
||||
<c:set var="cssMenu" value="active"/>
|
||||
</c:when>
|
||||
<c:otherwise>
|
||||
<c:set var="cssMenu" value=""/>
|
||||
</c:otherwise>
|
||||
</c:choose>
|
||||
<li class="${cssMenu}"><a href="<spring:url value="/vets.html" htmlEscape="true" />"><span class="glyphicon glyphicon-th-list" aria-hidden="true"></span><span> Veterinarians</span></a></li>
|
||||
<c:choose>
|
||||
<c:when test="${name eq 'error'}">
|
||||
<c:set var="cssMenu" value="active"/>
|
||||
</c:when>
|
||||
<c:otherwise>
|
||||
<c:set var="cssMenu" value=""/>
|
||||
</c:otherwise>
|
||||
</c:choose>
|
||||
<li class="${cssMenu}"><a href="<spring:url value="/oups.html" htmlEscape="true" />"
|
||||
title="trigger a RuntimeException to see how it is handled"><span class="glyphicon glyphicon-warning-sign" aria-hidden="true"></span><span> Error</span></a></li>
|
||||
|
||||
<petclinic:menuItem active="${name eq 'home'}" url="/" title="home page">
|
||||
<span class="glyphicon glyphicon-home" aria-hidden="true"></span>
|
||||
<span>Home</span>
|
||||
</petclinic:menuItem>
|
||||
|
||||
<petclinic:menuItem active="${name eq 'owners'}" url="/owners/find.html" title="find owners">
|
||||
<span class="glyphicon glyphicon-search" aria-hidden="true"></span>
|
||||
<span>Find owners</span>
|
||||
</petclinic:menuItem>
|
||||
|
||||
<petclinic:menuItem active="${name eq 'vets'}" url="/vets.html" title="veterinarians">
|
||||
<span class="glyphicon glyphicon-th-list" aria-hidden="true"></span>
|
||||
<span>Veterinarians</span>
|
||||
</petclinic:menuItem>
|
||||
|
||||
<petclinic:menuItem active="${name eq 'error'}" url="/oups.html"
|
||||
title="trigger a RuntimeException to see how it is handled">
|
||||
<span class="glyphicon glyphicon-warning-sign" aria-hidden="true"></span>
|
||||
<span>Error</span>
|
||||
</petclinic:menuItem>
|
||||
|
||||
</ul>
|
||||
</div> <%--/.nav-collapse --%>
|
||||
</div> <%--/.container-fluid --%>
|
||||
</div>
|
||||
</div>
|
||||
</nav>
|
||||
|
|
13
src/main/webapp/WEB-INF/tags/menuItem.tag
Normal file
13
src/main/webapp/WEB-INF/tags/menuItem.tag
Normal file
|
@ -0,0 +1,13 @@
|
|||
<%@ taglib prefix="spring" uri="http://www.springframework.org/tags" %>
|
||||
<%@ taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions" %>
|
||||
|
||||
<%@ attribute name="active" required="true" rtexprvalue="true" %>
|
||||
<%@ attribute name="url" required="true" rtexprvalue="true" %>
|
||||
<%@ attribute name="title" required="false" rtexprvalue="true" %>
|
||||
|
||||
<li class="${active ? 'active' : ''}">
|
||||
<a href="<spring:url value="${url}" htmlEscape="true" />"
|
||||
title="${fn:escapeXml(title)}">
|
||||
<jsp:doBody/>
|
||||
</a>
|
||||
</li>
|
Loading…
Reference in a new issue