Thymeleaf-ied layout and several JSP pages.

This commit is contained in:
Daniel Fernández
2012-12-19 20:55:03 +01:00
committed by Rossen Stoyanchev
parent d00d53793e
commit 72402f6f2d
8 changed files with 74 additions and 42 deletions

View File

@@ -7,7 +7,7 @@
http://www.springframework.org/schema/security http://www.springframework.org/schema/security/spring-security-3.1.xsd"> http://www.springframework.org/schema/security http://www.springframework.org/schema/security/spring-security-3.1.xsd">
<!-- Configure Spring Security --> <!-- Configure Spring Security -->
<security:http auto-config="true"> <security:http auto-config="true" use-expressions="true">
<security:form-login login-page="/login" login-processing-url="/loginProcess" <security:form-login login-page="/login" login-processing-url="/loginProcess"
default-target-url="/hotels/search" authentication-failure-url="/login?login_error=1" /> default-target-url="/hotels/search" authentication-failure-url="/login?login_error=1" />
<security:logout logout-url="/logout" logout-success-url="/logoutSuccess" /> <security:logout logout-url="/logout" logout-success-url="/logoutSuccess" />
@@ -34,4 +34,4 @@
</security:authentication-provider> </security:authentication-provider>
</security:authentication-manager> </security:authentication-manager>
</beans> </beans>

View File

@@ -0,0 +1,4 @@
<div tiles:include="searchForm"></div>
<div tiles:include="bookingsTable"></div>

View File

@@ -0,0 +1,35 @@
<h1>Search Hotels</h1>
<form action="#" th:object="${searchCriteria}" th:action="@{/hotels}" method="get" cssClass="inline">
<ul th:if="${#fields.hasErrors('*')}" class="errors span-18">
<li th:each="err : ${#fields.errors('*')}" th:text="${err}">Input is incorrect</li>
</ul>
<fieldset>
<div class="span-8">
<label for="searchString">Search String:</label>
<input type="text" id="searchString" th:field="*{searchString}" />
<script type="text/javascript">
Spring.addDecoration(new Spring.ElementDecoration({
elementId : "searchString",
widgetType : "dijit.form.ValidationTextBox",
widgetAttrs : { promptMessage : "Search hotels by name, address, city, or zip." }}));
</script>
</div>
<div class="span-6">
<div>
<label for="pageSize">Maximum results:</label>
<select id="pageSize" th:field="*{pageSize}">
<option label="5" value="5"/>
<option label="10" value="10"/>
<option label="20" value="20"/>
</select>
</div>
</div>
<div class="span-3 last">
<button type="submit">Find Hotels</button>
</div>
</fieldset>
</form>

View File

@@ -5,16 +5,16 @@
<tiles-definitions> <tiles-definitions>
<definition name="hotels/search" extends="standardLayout" templateType="jsp"> <definition name="hotels/search" extends="standardLayout">
<put-attribute name="body"> <put-attribute name="body">
<definition template="/WEB-INF/hotels/search.jsp" templateType="jsp"> <definition template="hotels/search.html" templateType="thymeleaf">
<put-attribute name="searchForm" value="/WEB-INF/hotels/searchForm.jsp" type="jsp"/> <put-attribute name="searchForm" value="hotels/searchForm.html" type="thymeleaf"/>
<put-attribute name="bookingsTable" value="/WEB-INF/hotels/bookingsTable.jsp" type="jsp"/> <put-attribute name="bookingsTable" value="/WEB-INF/hotels/bookingsTable.jsp" type="jsp"/>
</definition> </definition>
</put-attribute> </put-attribute>
</definition> </definition>
<definition name="hotels/*" extends="standardLayout" templateType="jsp"> <definition name="hotels/*" extends="standardLayout">
<put-attribute name="body" value="/WEB-INF/hotels/{1}.jsp" type="jsp"/> <put-attribute name="body" value="/WEB-INF/hotels/{1}.jsp" type="jsp"/>
</definition> </definition>

View File

@@ -1,10 +1,4 @@
<div xmlns:th="http://www.thymeleaf.org"> <div xmlns:th="http://www.thymeleaf.org">
<!-- Following this, we will see a conditional comment! -->
<!--[if lt IE 8]>
<link rel="stylesheet" href="/resources/blueprint/ie.css" type="text/css" media="screen, projection">
<p>
<![endif]-->
<h1>Welcome to Spring Travel</h1> <h1>Welcome to Spring Travel</h1>
<p> <p>
This sample demonstrates how to use Spring MVC and Spring Web Flow together with JavaServerPages (JSP) and Tiles. This sample demonstrates how to use Spring MVC and Spring Web Flow together with JavaServerPages (JSP) and Tiles.

View File

@@ -1,17 +1,20 @@
<!DOCTYPE html> <!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml" xmlns:th="http://www.thymeleaf.org" xml:lang="en" lang="en"> <html xmlns="http://www.w3.org/1999/xhtml"
xmlns:th="http://www.thymeleaf.org"
xmlns:tiles="http://www.thymeleaf.org"
xmlns:sec="http://www.thymeleaf.org"
lang="en">
<head> <head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>Spring Travel: Spring MVC and Web Flow Reference Application</title> <title>Spring Travel: Spring MVC and Web Flow Reference Application</title>
<link type="text/css" rel="stylesheet" href="#" th:href="@{/resources/dijit/themes/tundra/tundra.css}" /> <link type="text/css" rel="stylesheet" href="#" th:href="@{/resources/dijit/themes/tundra/tundra.css}" />
<link rel="stylesheet" href="#" th:href="@{/resources/styles/blueprint/screen.css}" type="text/css" media="screen, projection" /> <link rel="stylesheet" href="../../styles/blueprint/screen.css" th:href="@{/resources/styles/blueprint/screen.css}" type="text/css" media="screen, projection" />
<link rel="stylesheet" href="#" th:href="@{/resources/styles/blueprint/print.css}" type="text/css" media="print" /> <link rel="stylesheet" href="../../styles/blueprint/print.css" th:href="@{/resources/styles/blueprint/print.css}" type="text/css" media="print" />
<!--[if lt IE 8]> <!--[if lt IE 8]>
<link rel="stylesheet" href="../../styles/blueprint/ie.css" th:href="@{/resources/styles/blueprint/ie.css}" type="text/css" media="screen, projection" />
<link rel="stylesheet" href="<c:url value="/resources/blueprint/ie.css" />" type="text/css" media="screen, projection" />
<![endif]--> <![endif]-->
<link rel="stylesheet" href="#" th:href="@{/resources/styles/booking.css}" type="text/css" media="screen" /> <link rel="stylesheet" href="../../styles/booking.css" th:href="@{/resources/styles/booking.css}" type="text/css" media="screen" />
<script type="text/javascript" src="#" th:src="@{/resources/dojo/dojo.js}"></script> <script type="text/javascript" src="#" th:src="@{/resources/dojo/dojo.js}"></script>
<script type="text/javascript" src="#" th:src="@{/resources/spring/Spring.js}"></script> <script type="text/javascript" src="#" th:src="@{/resources/spring/Spring.js}"></script>
<script type="text/javascript" src="#" th:src="@{/resources/spring/Spring-Dojo.js}"></script> <script type="text/javascript" src="#" th:src="@{/resources/spring/Spring-Dojo.js}"></script>
@@ -22,22 +25,18 @@
<div id="page" class="container"> <div id="page" class="container">
<div id="header"> <div id="header">
<div id="topbar"> <div id="topbar">
<p> <p sec:authorize="hasRole('ROLE_USER')" th:if="${#authentication}">
<security:authorize ifAllGranted="ROLE_USER"> Welcome, <span sec:authentication="name">Dear User</span> |
<c:if test="${pageContext.request.userPrincipal != null}"> <a href="#" th:href="@{/logout}">Logout</a>
Welcome, ${pageContext.request.userPrincipal.name} | </p>
</c:if> <p sec:authorize="hasRole('ROLE_ANONYMOUS')">
<a href="<c:url value="/logout" />">Logout</a> <a href="#" th:href="@{/login}">Login</a>
</security:authorize>
<security:authorize ifAllGranted="ROLE_ANONYMOUS">
<a href="<c:url value="/login" />">Login</a>
</security:authorize>
</p> </p>
</div> </div>
<div id="logo"> <div id="logo">
<p> <p>
<a href="<c:url value="/" />"> <a href="#" th:href="@{/}">
<img src="<c:url value="/resources/images/header.jpg"/>" alt="Spring Travel" /> <img src="../../images/header.jpg" th:src="@{/resources/images/header.jpg}" alt="Spring Travel" />
</a> </a>
</p> </p>
</div> </div>
@@ -46,23 +45,23 @@
<div id="local" class="span-6"> <div id="local" class="span-6">
<p> <p>
<a href="http://www.thespringexperience.com"> <a href="http://www.thespringexperience.com">
<img src="<c:url value="/resources/images/diplomat.jpg"/>" alt="generic hotel" /> <img src="../../images/diplomat.jpg" th:src="@{/resources/images/diplomat.jpg}" alt="generic hotel" />
</a> </a>
</p> </p>
<p> <p>
<a href="http://www.thespringexperience.com"> <a href="http://www.thespringexperience.com">
<img src="<c:url value="/resources/images/springone2gx.jpeg"/>" alt="SpringOne 2GX" /> <img src="../../images/springone2gx.jpeg" th:src="@{/resources/images/springone2gx.jpeg}" alt="SpringOne 2GX" />
</a> </a>
</p> </p>
</div> </div>
<div id="main" class="span-18 last"> <div id="main" class="span-18 last" tiles:include="body">
<tiles:insertAttribute name="body" /> Body here...
</div> </div>
</div> </div>
<hr /> <hr />
<div id="footer"> <div id="footer">
<a href="http://www.springframework.org"> <a href="http://www.springframework.org">
<img src="<c:url value="/resources/images/powered-by-spring.png"/>" alt="Powered by Spring" /> <img src="../../images/powered-by-spring.png" th:src="@{/resources/images/powered-by-spring.png}" alt="Powered by Spring" />
</a> </a>
</div> </div>
</div> </div>

View File

@@ -5,6 +5,6 @@
<tiles-definitions> <tiles-definitions>
<definition name="standardLayout" template="/WEB-INF/layouts/standard.jsp" templateType="jsp"/> <definition name="standardLayout" template="layouts/standard.html" templateType="thymeleaf"/>
</tiles-definitions> </tiles-definitions>

View File

@@ -5,16 +5,16 @@
<tiles-definitions> <tiles-definitions>
<definition name="intro" extends="standardLayout" templateType="jsp"> <definition name="intro" extends="standardLayout">
<put-attribute name="body" value="intro.html"/> <put-attribute name="body" value="intro.html" type="thymeleaf"/>
</definition> </definition>
<definition name="login" extends="standardLayout" templateType="jsp"> <definition name="login" extends="standardLayout">
<put-attribute name="body" value="login.html"/> <put-attribute name="body" value="login.html" type="thymeleaf"/>
</definition> </definition>
<definition name="logoutSuccess" extends="standardLayout" templateType="jsp"> <definition name="logoutSuccess" extends="standardLayout">
<put-attribute name="body" value="logoutSuccess.html"/> <put-attribute name="body" value="logoutSuccess.html" type="thymeleaf"/>
</definition> </definition>
</tiles-definitions> </tiles-definitions>