Updated to work with Web Flow 2.0. Added Spring Security integration.
This commit is contained in:
@@ -0,0 +1,43 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<flow xmlns="http://www.springframework.org/schema/webflow"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://www.springframework.org/schema/webflow
|
||||
http://www.springframework.org/schema/webflow/spring-webflow-2.0.xsd">
|
||||
|
||||
<secured authorities="ROLE_USER" />
|
||||
|
||||
<persistence-context/>
|
||||
|
||||
<input name="${id}" value="${flowScope.id}" />
|
||||
|
||||
<on-start>
|
||||
<evaluate expression="${bookingService.findHotelById(flowScope.id)}" result="${flowScope.hotel}" />
|
||||
<evaluate expression="${hotel.createBooking(bookingService.findUser(currentUser.name))}" result="${flowScope.booking}" />
|
||||
</on-start>
|
||||
|
||||
<view-state id="enterBookingDetails" view="bookingForm.jsp">
|
||||
<on-render>
|
||||
<evaluate expression="${bookingActions.setupForm}"/>
|
||||
</on-render>
|
||||
<transition on="proceed" to="confirmBooking">
|
||||
<evaluate expression="${bookingActions.bindAndValidate}" />
|
||||
</transition>
|
||||
<transition on="cancel" to="cancel" />
|
||||
</view-state>
|
||||
|
||||
<view-state id="confirmBooking" view="confirmBooking.jsp">
|
||||
<on-render>
|
||||
<evaluate expression="${bookingActions.setupForm}"/>
|
||||
</on-render>
|
||||
<transition on="confirm" to="bookingAuthorized">
|
||||
<evaluate expression="${entityManager.persist(booking)}" />
|
||||
</transition>
|
||||
<transition on="revise" to="enterBookingDetails" />
|
||||
<transition on="cancel" to="cancel" />
|
||||
</view-state>
|
||||
|
||||
<end-state id="cancel"/>
|
||||
|
||||
<end-state id="bookingAuthorized" commit="true" />
|
||||
|
||||
</flow>
|
||||
@@ -0,0 +1,135 @@
|
||||
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
|
||||
<%@ taglib prefix="tiles" uri="http://tiles.apache.org/tags-tiles" %>
|
||||
<%@ taglib prefix="spring" uri="http://www.springframework.org/tags" %>
|
||||
<%@ taglib prefix="form" uri="http://www.springframework.org/tags/form" %>
|
||||
<!DOCTYPE composition PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
|
||||
<tiles:insertTemplate template="/WEB-INF/layouts/standard.jsp">
|
||||
<tiles:putAttribute name="content">
|
||||
|
||||
<div class="section">
|
||||
<h1>Book Hotel</h1>
|
||||
</div>
|
||||
|
||||
<div class="section">
|
||||
<form:form id="booking" modelAttribute="booking">
|
||||
<form:errors path="*" cssClass="errors" />
|
||||
<fieldset>
|
||||
<div class="field">
|
||||
<div class="label">Name:</div>
|
||||
<div class="output">${hotel.name}</div>
|
||||
</div>
|
||||
<div class="field">
|
||||
<div class="label">Address:</div>
|
||||
<div class="output">${hotel.address}</div>
|
||||
</div>
|
||||
<div class="field">
|
||||
<div class="label">City, State:</div>
|
||||
<div class="output">${hotel.city}, ${hotel.state}</div>
|
||||
</div>
|
||||
<div class="field">
|
||||
<div class="label">Zip:</div>
|
||||
<div class="output">${hotel.zip}</div>
|
||||
</div>
|
||||
<div class="field">
|
||||
<div class="label">Country:</div>
|
||||
<div class="output">${hotel.country}</div>
|
||||
</div>
|
||||
<div class="field">
|
||||
<div class="label">Nightly rate:</div>
|
||||
<div class="output">
|
||||
<spring:bind path="hotel.price">${status.value}</spring:bind>
|
||||
</div>
|
||||
</div>
|
||||
<div class="field">
|
||||
<div class="label">
|
||||
<label for="checkinDate">Check In Date:</label>
|
||||
</div>
|
||||
<div class="input">
|
||||
<form:errors path="checkinDate" cssClass="errors"/>
|
||||
<form:input path="checkinDate"/>
|
||||
</div>
|
||||
</div>
|
||||
<div class="field">
|
||||
<div class="label">
|
||||
<label for="checkoutDate">Check Out Date:</label>
|
||||
</div>
|
||||
<div class="input">
|
||||
<form:errors path="checkoutDate" cssClass="errors"/>
|
||||
<form:input path="checkoutDate"/>
|
||||
</div>
|
||||
</div>
|
||||
<div class="field">
|
||||
<div class="label">
|
||||
<label for="beds">Room Preference:</label>
|
||||
</div>
|
||||
<div class="input">
|
||||
<form:select id="beds" path="beds">
|
||||
<form:option label="One king-size bed" value="1"/>
|
||||
<form:option label="Two double beds" value="2"/>
|
||||
<form:option label="Three beds" value="3"/>
|
||||
</form:select>
|
||||
</div>
|
||||
</div>
|
||||
<div class="field">
|
||||
<div class="label">
|
||||
<label for="smoking">Smoking Preference:</label>
|
||||
</div>
|
||||
<div id="radio" class="input">
|
||||
<form:radiobutton id="smoking" path="smoking" label="Smoking" value="true"/>
|
||||
<form:radiobutton path="smoking" label="Non Smoking" value="false"/>
|
||||
</div>
|
||||
</div>
|
||||
<div class="field">
|
||||
<div class="label">
|
||||
<label for="creditCard">Credit Card #:</label>
|
||||
</div>
|
||||
<div class="input">
|
||||
<form:errors path="creditCard" cssClass="errors"/>
|
||||
<form:input id="creditCard" path="creditCard"/>
|
||||
</div>
|
||||
</div>
|
||||
<div class="field">
|
||||
<div class="label">
|
||||
<label for="creditCardName">Credit Card Name:</label>
|
||||
</div>
|
||||
<div class="input">
|
||||
<form:errors path="creditCardName" cssClass="errors"/>
|
||||
<form:input id="creditCardName" path="creditCardName"/>
|
||||
</div>
|
||||
</div>
|
||||
<div class="field">
|
||||
<div class="label">
|
||||
<label for="creditCardExpiryMonth">Credit Card Expirty:</label>
|
||||
</div>
|
||||
<div class="input">
|
||||
<form:select id="creditCardExpiryMonth" path="creditCardExpiryMonth">
|
||||
<form:option label="Jan" value="1"/>
|
||||
<form:option label="Feb" value="2"/>
|
||||
<form:option label="Mar" value="3"/>
|
||||
<form:option label="Apr" value="4"/>
|
||||
<form:option label="May" value="5"/>
|
||||
<form:option label="Jun" value="6"/>
|
||||
<form:option label="Jul" value="7"/>
|
||||
<form:option label="Aug" value="8"/>
|
||||
<form:option label="Sep" value="9"/>
|
||||
<form:option label="Oct" value="10"/>
|
||||
<form:option label="Nov" value="11"/>
|
||||
<form:option label="Dec" value="12"/>
|
||||
</form:select>
|
||||
<form:select path="creditCardExpiryYear">
|
||||
<form:option label="2007" value="1"/>
|
||||
<form:option label="2008" value="2"/>
|
||||
<form:option label="2009" value="3"/>
|
||||
</form:select>
|
||||
</div>
|
||||
</div>
|
||||
<div class="buttonGroup">
|
||||
<input type="submit" name="_eventId_proceed" value="Proceed"/> 
|
||||
<input type="submit" name="_eventId_cancel" value="Cancel"/> 
|
||||
</div>
|
||||
</fieldset>
|
||||
</form:form>
|
||||
</div>
|
||||
|
||||
</tiles:putAttribute>
|
||||
</tiles:insertTemplate>
|
||||
@@ -0,0 +1,68 @@
|
||||
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
|
||||
<%@ taglib prefix="tiles" uri="http://tiles.apache.org/tags-tiles" %>
|
||||
<%@ taglib prefix="spring" uri="http://www.springframework.org/tags" %>
|
||||
<%@ taglib prefix="form" uri="http://www.springframework.org/tags/form" %>
|
||||
<!DOCTYPE composition PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
|
||||
<tiles:insertTemplate template="/WEB-INF/layouts/standard.jsp">
|
||||
<tiles:putAttribute name="content">
|
||||
|
||||
<div class="section">
|
||||
<h1>Confirm Hotel Booking</h1>
|
||||
</div>
|
||||
|
||||
<div class="section">
|
||||
<form:form id="confirm" modelAttribute="booking">
|
||||
<fieldset>
|
||||
<div class="field">
|
||||
<div class="label">Name:</div>
|
||||
<div class="output">${hotel.name}</div>
|
||||
</div>
|
||||
<div class="field">
|
||||
<div class="label">Address:</div>
|
||||
<div class="output">${hotel.address}</div>
|
||||
</div>
|
||||
<div class="field">
|
||||
<div class="label">City, State:</div>
|
||||
<div class="output">${hotel.city}, ${hotel.state}</div>
|
||||
</div>
|
||||
<div class="field">
|
||||
<div class="label">Zip:</div>
|
||||
<div class="output">${hotel.zip}</div>
|
||||
</div>
|
||||
<div class="field">
|
||||
<div class="label">Country:</div>
|
||||
<div class="output">${hotel.country}</div>
|
||||
</div>
|
||||
<div class="field">
|
||||
<div class="label">Total payment:</div>
|
||||
<div class="output">
|
||||
<spring:bind path="total">${status.value}</spring:bind>
|
||||
</div>
|
||||
</div>
|
||||
<div class="field">
|
||||
<div class="label">Check In Date:</div>
|
||||
<div class="output">
|
||||
<spring:bind path="checkinDate">${status.value}</spring:bind>
|
||||
</div>
|
||||
</div>
|
||||
<div class="field">
|
||||
<div class="label">Check Out Date:</div>
|
||||
<div class="output">
|
||||
<spring:bind path="checkoutDate">${status.value}</spring:bind>
|
||||
</div>
|
||||
</div>
|
||||
<div class="field">
|
||||
<div class="label">Credit Card #:</div>
|
||||
<div class="output">${booking.creditCard}</div>
|
||||
</div>
|
||||
<div class="buttonGroup">
|
||||
<input type="submit" name="_eventId_confirm" value="Confim"/> 
|
||||
<input type="submit" name="_eventId_revise" value="Revise"/> 
|
||||
<input type="submit" name="_eventId_cancel" value="Cancel"/> 
|
||||
</div>
|
||||
</fieldset>
|
||||
</form:form>
|
||||
</div>
|
||||
|
||||
</tiles:putAttribute>
|
||||
</tiles:insertTemplate>
|
||||
@@ -0,0 +1,55 @@
|
||||
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
|
||||
<%@ taglib prefix="tiles" uri="http://tiles.apache.org/tags-tiles" %>
|
||||
<%@ taglib prefix="spring" uri="http://www.springframework.org/tags" %>
|
||||
<%@ taglib prefix="form" uri="http://www.springframework.org/tags/form" %>
|
||||
<!DOCTYPE composition PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
|
||||
<tiles:insertTemplate template="/WEB-INF/layouts/standard.jsp">
|
||||
<tiles:putAttribute name="content">
|
||||
|
||||
<div class="section">
|
||||
<h1>View Hotel</h1>
|
||||
</div>
|
||||
|
||||
<div class="section">
|
||||
<form:form id="hotel" modelAttribute="hotel">
|
||||
<fieldset>
|
||||
<div class="field">
|
||||
<div class="label">Name:</div>
|
||||
<div class="output">${hotel.name}</div>
|
||||
</div>
|
||||
<div class="field">
|
||||
<div class="label">Address:</div>
|
||||
<div class="output">${hotel.address}</div>
|
||||
</div>
|
||||
<div class="field">
|
||||
<div class="label">City:</div>
|
||||
<div class="output">${hotel.city}</div>
|
||||
</div>
|
||||
<div class="field">
|
||||
<div class="label">State:</div>
|
||||
<div class="output">${hotel.state}</div>
|
||||
</div>
|
||||
<div class="field">
|
||||
<div class="label">Zip:</div>
|
||||
<div class="output">${hotel.zip}</div>
|
||||
</div>
|
||||
<div class="field">
|
||||
<div class="label">Country:</div>
|
||||
<div class="output">${hotel.country}</div>
|
||||
</div>
|
||||
<div class="field">
|
||||
<div class="label">Nightly rate:</div>
|
||||
<div class="output">
|
||||
<spring:bind path="price">${status.value}</spring:bind>
|
||||
</div>
|
||||
</div>
|
||||
<div class="buttonGroup">
|
||||
<input type="submit" name="_eventId_book" value="Book Hotel"/> 
|
||||
<input type="submit" name="_eventId_cancel" value="Back to Search"/> 
|
||||
</div>
|
||||
</fieldset>
|
||||
</form:form>
|
||||
</div>
|
||||
|
||||
</tiles:putAttribute>
|
||||
</tiles:insertTemplate>
|
||||
104
spring-webflow-samples/booking-mvc/src/main/webapp/WEB-INF/flow/main/main.jsp
Executable file
104
spring-webflow-samples/booking-mvc/src/main/webapp/WEB-INF/flow/main/main.jsp
Executable file
@@ -0,0 +1,104 @@
|
||||
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
|
||||
<%@ taglib prefix="tiles" uri="http://tiles.apache.org/tags-tiles" %>
|
||||
<%@ taglib prefix="form" uri="http://www.springframework.org/tags/form" %>
|
||||
<%@ taglib prefix="security" uri="http://www.springframework.org/security/tags" %>
|
||||
<!DOCTYPE composition PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
|
||||
<tiles:insertTemplate template="/WEB-INF/layouts/standard.jsp">
|
||||
<tiles:putAttribute name="content">
|
||||
|
||||
<form:form modelAttribute="searchCriteria">
|
||||
<div class="section">
|
||||
<span class="errors">
|
||||
<form:errors path="*"/>
|
||||
</span>
|
||||
<h1>Search Hotels</h1>
|
||||
<fieldset>
|
||||
<form:input path="searchString"/>
|
||||
<label for="pageSize">Maximum results:</label>
|
||||
<form:select path="pageSize">
|
||||
<form:option label="5" value="5"/>
|
||||
<form:option label="10" value="10"/>
|
||||
<form:option label="20" value="20"/>
|
||||
</form:select>
|
||||
<input type="submit" class="button" name="_eventId_findHotels" value="Find Hotels" />
|
||||
</fieldset>
|
||||
</div>
|
||||
</form:form>
|
||||
|
||||
<c:if test="${not empty searchCriteria.searchString}">
|
||||
<div class="section">
|
||||
<table class="summary">
|
||||
<thead>
|
||||
<tr>
|
||||
<th>Name</th>
|
||||
<th>Address</th>
|
||||
<th>City, State</th>
|
||||
<th>Zip</th>
|
||||
<th>Action</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<c:forEach var="hotel" items="${hotels}">
|
||||
<tr>
|
||||
<td>${hotel.name}</td>
|
||||
<td>${hotel.address}</td>
|
||||
<td>${hotel.city}, ${hotel.state}, ${hotel.country}</td>
|
||||
<td>${hotel.zip}</td>
|
||||
<td>
|
||||
<a href="${flowExecutionUrl}&_eventId=selectHotel&hotelId=${hotel.id}">View Hotel</a>
|
||||
</td>
|
||||
</tr>
|
||||
</c:forEach>
|
||||
<c:if test="${empty hotels}">
|
||||
<tr>
|
||||
<td colspan="5">No hotels found</td>
|
||||
</tr>
|
||||
</c:if>
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
</c:if>
|
||||
|
||||
<security:authorize ifAllGranted="ROLE_USER">
|
||||
<div class="section">
|
||||
<h1>Current Hotel Bookings</h1>
|
||||
|
||||
<table class="summary">
|
||||
<thead>
|
||||
<tr>
|
||||
<th>Name</th>
|
||||
<th>Address</th>
|
||||
<th>City, State</th>
|
||||
<th>Check in Date</th>
|
||||
<th>Check out Date</th>
|
||||
<th>Confirmation Number</th>
|
||||
<th>Action</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<c:forEach var="booking" items="${bookings}">
|
||||
<tr>
|
||||
<td>${booking.hotel.name}</td>
|
||||
<td>${booking.hotel.address}</td>
|
||||
<td>${booking.hotel.city}, ${booking.hotel.state}</td>
|
||||
<td>${booking.checkinDate}</td>
|
||||
<td>${booking.checkoutDate}</td>
|
||||
<td>${booking.id}</td>
|
||||
<td>
|
||||
<a href="${flowExecutionUrl}&_eventId=cancelBooking&bookingId=${booking.id}">Cancel</a>
|
||||
</td>
|
||||
</tr>
|
||||
</c:forEach>
|
||||
<c:if test="${empty bookings}">
|
||||
<tr>
|
||||
<td colspan="7">No booking history</td>
|
||||
</tr>
|
||||
</c:if>
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
</security:authorize>
|
||||
|
||||
|
||||
</tiles:putAttribute>
|
||||
</tiles:insertTemplate>
|
||||
@@ -0,0 +1,44 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<flow xmlns="http://www.springframework.org/schema/webflow"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://www.springframework.org/schema/webflow
|
||||
http://www.springframework.org/schema/webflow/spring-webflow-2.0.xsd">
|
||||
|
||||
<var name="searchCriteria" class="org.springframework.webflow.samples.booking.SearchCriteria" />
|
||||
|
||||
<view-state id="displayMain" view="main.jsp">
|
||||
<on-render>
|
||||
<evaluate expression="${bookingService.findBookings(currentUser.name)}" result="${requestScope.bookings}" />
|
||||
</on-render>
|
||||
<transition on="findHotels" to="findHotels">
|
||||
<evaluate expression="${mainActions.bindAndValidate}" />
|
||||
</transition>
|
||||
<transition on="selectHotel" to="displayHotel">
|
||||
<set name="${requestScope.id}" value="${requestParameters.hotelId}" type="long" />
|
||||
<evaluate expression="${bookingService.findHotelById(id)}" result="${flowScope.hotel}" />
|
||||
</transition>
|
||||
<transition on="cancelBooking" to="cancelBooking" />
|
||||
</view-state>
|
||||
|
||||
<action-state id="findHotels">
|
||||
<evaluate expression="${bookingService.findHotels(searchCriteria)}" result="${flowScope.hotels}" />
|
||||
<transition on="success" to="displayMain" />
|
||||
</action-state>
|
||||
|
||||
<view-state id="displayHotel" view="hotelDetails.jsp">
|
||||
<transition on="book" to="bookHotel" />
|
||||
<transition on="cancel" to="cancel" />
|
||||
</view-state>
|
||||
|
||||
<subflow-state id="bookHotel" subflow="booking">
|
||||
<input name="${id}" value="${flowScope.hotel.id}" />
|
||||
<transition on="bookingAuthorized" to="displayMain" />
|
||||
<transition on="cancel" to="displayMain" />
|
||||
</subflow-state>
|
||||
|
||||
<action-state id="cancelBooking">
|
||||
<evaluate expression="${bookingService.cancelBooking(requestParameters.bookingId)}" />
|
||||
<transition on="success" to="displayMain" />
|
||||
</action-state>
|
||||
|
||||
</flow>
|
||||
Reference in New Issue
Block a user