mvc + swf

This commit is contained in:
Keith Donald
2008-03-27 11:44:07 +00:00
parent d239366392
commit c563cb5ce7
8 changed files with 236 additions and 6 deletions

View File

@@ -0,0 +1,16 @@
package org.springframework.webflow.samples.booking;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.springframework.web.servlet.ModelAndView;
import org.springframework.web.servlet.view.RedirectView;
import org.springframework.webflow.core.collection.AttributeMap;
import org.springframework.webflow.mvc.AbstractFlowHandler;
public class BookingFlowHandler extends AbstractFlowHandler {
public ModelAndView handleExecutionOutcome(String outcome, AttributeMap output, HttpServletRequest request,
HttpServletResponse response) {
return new ModelAndView(new RedirectView("/spring/hotels/index", true));
}
}

View File

@@ -0,0 +1,32 @@
package org.springframework.webflow.samples.booking;
import java.util.List;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
public class HotelsController {
private BookingService bookingService;
public HotelsController(BookingService bookingService) {
this.bookingService = bookingService;
}
@RequestMapping(method = RequestMethod.GET)
public void index(SearchCriteria searchCriteria) {
}
@RequestMapping
@ModelAttribute("hotels")
public List<Hotel> search(SearchCriteria criteria) {
return bookingService.findHotels(criteria);
}
@RequestMapping(method = RequestMethod.GET)
public Hotel show(@RequestParam("id") Long id) {
return bookingService.findHotelById(id);
}
}

View File

@@ -7,7 +7,7 @@
<persistence-context/>
<input name="hotelId" value="flowScope.hotelId" />
<input name="hotelId" value="flowScope.hotelId" required="true"/>
<on-start>
<evaluate expression="bookingService.createBooking(hotelId, currentUser.name)" result="flowScope.booking" />

View File

@@ -0,0 +1,69 @@
<%@ 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" %>
<tiles:insertTemplate template="/WEB-INF/layouts/standard.jsp">
<tiles:putAttribute name="content">
<form:form modelAttribute="searchCriteria" action="search">
<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" value="Find Hotels" />
</fieldset>
</div>
</form:form>
<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="deleteBooking?id=${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>

View File

@@ -0,0 +1,47 @@
<%@ 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" %>
<tiles:insertTemplate template="/WEB-INF/layouts/standard.jsp">
<tiles:putAttribute name="content">
<div class="section">
<h1>Hotel Results</h1>
</div>
<c:if test="${not empty hotels}">
<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="show?id=${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>
</tiles:putAttribute>
</tiles:insertTemplate>

View File

@@ -0,0 +1,56 @@
<%@ 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" %>
<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" action="booking" method="get">
<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>
<input type="hidden" name="hotelId" value="${hotel.id}" />
<div class="buttonGroup">
<input type="submit" value="Book Hotel"/>&#160;
<input type="submit" value="Back to Search"/>&#160;
</div>
</fieldset>
</form:form>
</div>
</tiles:putAttribute>
</tiles:insertTemplate>

View File

@@ -18,8 +18,8 @@
<bean class="org.springframework.web.servlet.handler.SimpleUrlHandlerMapping">
<property name="mappings">
<value>
/main=flowController
/booking=flowController
/hotels/booking=bookingFlowHandler
/hotels/*=hotelsController
</value>
</property>
<property name="defaultHandler">
@@ -28,11 +28,21 @@
</property>
</bean>
<!-- Handles requests mapped to the Spring Web Flow system -->
<bean id="flowController" class="org.springframework.webflow.mvc.FlowController">
<!-- Handles requests to search hotels and display hotel details -->
<bean id="hotelsController" class="org.springframework.webflow.samples.booking.HotelsController">
<constructor-arg ref="bookingService"/>
</bean>
<!-- Controls access to the booking flow -->
<bean id="bookingFlowHandler" class="org.springframework.webflow.samples.booking.BookingFlowHandler" />
<!-- Handles requests mapped to the Web Flow handlers -->
<bean class="org.springframework.webflow.mvc.FlowHandlerAdapter">
<constructor-arg ref="flowExecutor" />
</bean>
<bean class="org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter"/>
<!-- Executes flows: the central entry point into the Spring Web Flow system -->
<web:flow-executor id="flowExecutor" flow-registry="flowRegistry">
<web:flow-execution-listeners>

View File

@@ -1,5 +1,5 @@
<html>
<head>
<meta http-equiv="Refresh" content="0; URL=spring/intro">
<meta http-equiv="Refresh" content="0; URL=spring/hotels/index">
</head>
</html>