From 9fd402fbc7dc80284c95614434032670023c346d Mon Sep 17 00:00:00 2001 From: Rossen Stoyanchev Date: Wed, 5 May 2010 20:48:18 +0000 Subject: [PATCH] SWF-1219 Update booking-mvc sample to use template URLs with path variables, the Spring MVC namespace, the HiddenHttpMethodFilter, and the spring:url tag. --- .../samples/booking/BookingFlowHandler.java | 6 +- .../samples/booking/HotelsController.java | 25 +++---- .../webapp/WEB-INF/config/security-config.xml | 2 +- .../webapp/WEB-INF/config/webmvc-config.xml | 25 +++---- .../WEB-INF/hotels/booking/booking-flow.xml | 2 +- .../webapp/WEB-INF/hotels/bookingsTable.jsp | 16 ++--- .../webapp/WEB-INF/hotels/hotelSearchForm.jsp | 4 +- .../src/main/webapp/WEB-INF/hotels/index.jsp | 5 -- .../src/main/webapp/WEB-INF/hotels/list.jsp | 72 +++++++++++++++++++ .../src/main/webapp/WEB-INF/hotels/search.jsp | 71 +----------------- .../src/main/webapp/WEB-INF/hotels/show.jsp | 2 +- .../src/main/webapp/WEB-INF/hotels/views.xml | 4 +- .../src/main/webapp/WEB-INF/intro.jsp | 2 +- .../main/webapp/WEB-INF/layouts/standard.jsp | 2 - .../src/main/webapp/WEB-INF/login.jsp | 7 +- .../src/main/webapp/WEB-INF/logoutSuccess.jsp | 2 +- .../src/main/webapp/WEB-INF/web.xml | 15 +++- 17 files changed, 134 insertions(+), 128 deletions(-) delete mode 100644 spring-webflow-samples/booking-mvc/src/main/webapp/WEB-INF/hotels/index.jsp create mode 100644 spring-webflow-samples/booking-mvc/src/main/webapp/WEB-INF/hotels/list.jsp diff --git a/spring-webflow-samples/booking-mvc/src/main/java/org/springframework/webflow/samples/booking/BookingFlowHandler.java b/spring-webflow-samples/booking-mvc/src/main/java/org/springframework/webflow/samples/booking/BookingFlowHandler.java index cc675ed2..726f2bd7 100644 --- a/spring-webflow-samples/booking-mvc/src/main/java/org/springframework/webflow/samples/booking/BookingFlowHandler.java +++ b/spring-webflow-samples/booking-mvc/src/main/java/org/springframework/webflow/samples/booking/BookingFlowHandler.java @@ -10,16 +10,18 @@ import org.springframework.webflow.mvc.servlet.AbstractFlowHandler; public class BookingFlowHandler extends AbstractFlowHandler { + private static final String DEFAULT_URL = "/hotels/search"; + @Override public String handleExecutionOutcome(FlowExecutionOutcome outcome, HttpServletRequest request, HttpServletResponse response) { - return "/hotels/index"; + return DEFAULT_URL; } @Override public String handleException(FlowException e, HttpServletRequest request, HttpServletResponse response) { if (e instanceof NoSuchFlowExecutionException) { - return "/hotels/index"; + return DEFAULT_URL; } else { throw e; } diff --git a/spring-webflow-samples/booking-mvc/src/main/java/org/springframework/webflow/samples/booking/HotelsController.java b/spring-webflow-samples/booking-mvc/src/main/java/org/springframework/webflow/samples/booking/HotelsController.java index 308c6150..fb49728f 100644 --- a/spring-webflow-samples/booking-mvc/src/main/java/org/springframework/webflow/samples/booking/HotelsController.java +++ b/spring-webflow-samples/booking-mvc/src/main/java/org/springframework/webflow/samples/booking/HotelsController.java @@ -6,9 +6,9 @@ import java.util.List; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Controller; import org.springframework.ui.Model; +import org.springframework.web.bind.annotation.PathVariable; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMethod; -import org.springframework.web.bind.annotation.RequestParam; @Controller public class HotelsController { @@ -20,30 +20,31 @@ public class HotelsController { this.bookingService = bookingService; } - @RequestMapping(method = RequestMethod.GET) - public void index(SearchCriteria searchCriteria, Principal currentUser, Model model) { + @RequestMapping(value = "/hotels/search", method = RequestMethod.GET) + public void search(SearchCriteria searchCriteria, Principal currentUser, Model model) { if (currentUser != null) { List booking = bookingService.findBookings(currentUser.getName()); model.addAttribute(booking); } } - @RequestMapping(method = RequestMethod.GET) - public String search(SearchCriteria criteria, Model model) { + @RequestMapping(value = "/hotels", method = RequestMethod.GET) + public String list(SearchCriteria criteria, Model model) { List hotels = bookingService.findHotels(criteria); model.addAttribute(hotels); - return "hotels/search"; + return "hotels/list"; } - @RequestMapping(method = RequestMethod.GET) - public Hotel show(@RequestParam("id") Long id) { - return bookingService.findHotelById(id); + @RequestMapping(value = "/hotels/{id}", method = RequestMethod.GET) + public String show(@PathVariable Long id, Model model) { + model.addAttribute(bookingService.findHotelById(id)); + return "hotels/show"; } - @RequestMapping(method = RequestMethod.GET) - public String deleteBooking(@RequestParam("id") Long id) { + @RequestMapping(value = "/bookings/{id}", method = RequestMethod.DELETE) + public String deleteBooking(@PathVariable Long id) { bookingService.cancelBooking(id); - return "redirect:index"; + return "redirect:../hotels/search"; } } diff --git a/spring-webflow-samples/booking-mvc/src/main/webapp/WEB-INF/config/security-config.xml b/spring-webflow-samples/booking-mvc/src/main/webapp/WEB-INF/config/security-config.xml index b362bba5..cccf9015 100644 --- a/spring-webflow-samples/booking-mvc/src/main/webapp/WEB-INF/config/security-config.xml +++ b/spring-webflow-samples/booking-mvc/src/main/webapp/WEB-INF/config/security-config.xml @@ -11,7 +11,7 @@ + default-target-url="/spring/hotels/search" authentication-failure-url="/spring/login?login_error=1" /> diff --git a/spring-webflow-samples/booking-mvc/src/main/webapp/WEB-INF/config/webmvc-config.xml b/spring-webflow-samples/booking-mvc/src/main/webapp/WEB-INF/config/webmvc-config.xml index d0f4eecd..b7bbdeec 100644 --- a/spring-webflow-samples/booking-mvc/src/main/webapp/WEB-INF/config/webmvc-config.xml +++ b/spring-webflow-samples/booking-mvc/src/main/webapp/WEB-INF/config/webmvc-config.xml @@ -5,20 +5,19 @@ xsi:schemaLocation="http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-3.0.xsd http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd"> - + + + + - + - - - - - - - - + + + + @@ -35,12 +34,6 @@ - - - - - - diff --git a/spring-webflow-samples/booking-mvc/src/main/webapp/WEB-INF/hotels/booking/booking-flow.xml b/spring-webflow-samples/booking-mvc/src/main/webapp/WEB-INF/hotels/booking/booking-flow.xml index b97f51ff..c80c7ec1 100644 --- a/spring-webflow-samples/booking-mvc/src/main/webapp/WEB-INF/hotels/booking/booking-flow.xml +++ b/spring-webflow-samples/booking-mvc/src/main/webapp/WEB-INF/hotels/booking/booking-flow.xml @@ -35,7 +35,7 @@ - + diff --git a/spring-webflow-samples/booking-mvc/src/main/webapp/WEB-INF/hotels/bookingsTable.jsp b/spring-webflow-samples/booking-mvc/src/main/webapp/WEB-INF/hotels/bookingsTable.jsp index 7e013d7a..d3773183 100644 --- a/spring-webflow-samples/booking-mvc/src/main/webapp/WEB-INF/hotels/bookingsTable.jsp +++ b/spring-webflow-samples/booking-mvc/src/main/webapp/WEB-INF/hotels/bookingsTable.jsp @@ -1,5 +1,7 @@ <%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %> <%@ taglib prefix="security" uri="http://www.springframework.org/security/tags" %> +<%@ taglib prefix="spring" uri="http://www.springframework.org/tags" %> +<%@ taglib prefix="form" uri="http://www.springframework.org/tags/form" %>
@@ -34,14 +36,12 @@ ${booking.checkoutDate} ${booking.id} - Cancel - + + + + + + diff --git a/spring-webflow-samples/booking-mvc/src/main/webapp/WEB-INF/hotels/hotelSearchForm.jsp b/spring-webflow-samples/booking-mvc/src/main/webapp/WEB-INF/hotels/hotelSearchForm.jsp index a84866a9..ea4a9ff8 100644 --- a/spring-webflow-samples/booking-mvc/src/main/webapp/WEB-INF/hotels/hotelSearchForm.jsp +++ b/spring-webflow-samples/booking-mvc/src/main/webapp/WEB-INF/hotels/hotelSearchForm.jsp @@ -1,6 +1,8 @@ <%@ taglib prefix="form" uri="http://www.springframework.org/tags/form" %> +<%@ taglib prefix="c" uri="http://java.sun.com/jstl/core" %> - + +
diff --git a/spring-webflow-samples/booking-mvc/src/main/webapp/WEB-INF/hotels/index.jsp b/spring-webflow-samples/booking-mvc/src/main/webapp/WEB-INF/hotels/index.jsp deleted file mode 100644 index 6c11411f..00000000 --- a/spring-webflow-samples/booking-mvc/src/main/webapp/WEB-INF/hotels/index.jsp +++ /dev/null @@ -1,5 +0,0 @@ -<%@ taglib prefix="tiles" uri="http://tiles.apache.org/tags-tiles" %> - - - - diff --git a/spring-webflow-samples/booking-mvc/src/main/webapp/WEB-INF/hotels/list.jsp b/spring-webflow-samples/booking-mvc/src/main/webapp/WEB-INF/hotels/list.jsp new file mode 100644 index 00000000..76c6c9a3 --- /dev/null +++ b/spring-webflow-samples/booking-mvc/src/main/webapp/WEB-INF/hotels/list.jsp @@ -0,0 +1,72 @@ +<%@ taglib prefix="tiles" uri="http://tiles.apache.org/tags-tiles" %> +<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %> +<%@ taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions"%> + +
+

Hotel Results

+
+

+Change Search + +

+
+ + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameAddressCity, StateZipAction
${hotel.name}${hotel.address}${hotel.city}, ${hotel.state}, ${hotel.country}${hotel.zip}View Hotel
No hotels found
+
+ + Previous Results + + + + More Results + + +
+
+
+ diff --git a/spring-webflow-samples/booking-mvc/src/main/webapp/WEB-INF/hotels/search.jsp b/spring-webflow-samples/booking-mvc/src/main/webapp/WEB-INF/hotels/search.jsp index f9ce1b4e..6c11411f 100644 --- a/spring-webflow-samples/booking-mvc/src/main/webapp/WEB-INF/hotels/search.jsp +++ b/spring-webflow-samples/booking-mvc/src/main/webapp/WEB-INF/hotels/search.jsp @@ -1,72 +1,5 @@ <%@ taglib prefix="tiles" uri="http://tiles.apache.org/tags-tiles" %> -<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %> -<%@ taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions"%> -
-

Hotel Results

-
-

-Change Search - -

-
- - - - - - - - - - - - - - - - - - - - - - - - - - - -
NameAddressCity, StateZipAction
${hotel.name}${hotel.address}${hotel.city}, ${hotel.state}, ${hotel.country}${hotel.zip}View Hotel
No hotels found
-
- - Previous Results - - - - More Results - - -
-
-
+ + diff --git a/spring-webflow-samples/booking-mvc/src/main/webapp/WEB-INF/hotels/show.jsp b/spring-webflow-samples/booking-mvc/src/main/webapp/WEB-INF/hotels/show.jsp index 76ce8aa1..3e33ab0d 100644 --- a/spring-webflow-samples/booking-mvc/src/main/webapp/WEB-INF/hotels/show.jsp +++ b/spring-webflow-samples/booking-mvc/src/main/webapp/WEB-INF/hotels/show.jsp @@ -7,7 +7,7 @@
- +
Name:
diff --git a/spring-webflow-samples/booking-mvc/src/main/webapp/WEB-INF/hotels/views.xml b/spring-webflow-samples/booking-mvc/src/main/webapp/WEB-INF/hotels/views.xml index 0d354a32..b015d388 100644 --- a/spring-webflow-samples/booking-mvc/src/main/webapp/WEB-INF/hotels/views.xml +++ b/spring-webflow-samples/booking-mvc/src/main/webapp/WEB-INF/hotels/views.xml @@ -5,9 +5,9 @@ - + - + diff --git a/spring-webflow-samples/booking-mvc/src/main/webapp/WEB-INF/intro.jsp b/spring-webflow-samples/booking-mvc/src/main/webapp/WEB-INF/intro.jsp index 3feba873..666e4860 100755 --- a/spring-webflow-samples/booking-mvc/src/main/webapp/WEB-INF/intro.jsp +++ b/spring-webflow-samples/booking-mvc/src/main/webapp/WEB-INF/intro.jsp @@ -23,6 +23,6 @@
  • Spring IDE tooling integration, with support for graphical flow modeling and visualization
  • - Start your Spring Travel experience + Start your Spring Travel experience

    diff --git a/spring-webflow-samples/booking-mvc/src/main/webapp/WEB-INF/layouts/standard.jsp b/spring-webflow-samples/booking-mvc/src/main/webapp/WEB-INF/layouts/standard.jsp index 0ecf6024..0187a9c1 100644 --- a/spring-webflow-samples/booking-mvc/src/main/webapp/WEB-INF/layouts/standard.jsp +++ b/spring-webflow-samples/booking-mvc/src/main/webapp/WEB-INF/layouts/standard.jsp @@ -48,8 +48,6 @@ " alt="The Spring Experience" /> -

    -

    diff --git a/spring-webflow-samples/booking-mvc/src/main/webapp/WEB-INF/login.jsp b/spring-webflow-samples/booking-mvc/src/main/webapp/WEB-INF/login.jsp index 57a45ad6..ace2bd36 100755 --- a/spring-webflow-samples/booking-mvc/src/main/webapp/WEB-INF/login.jsp +++ b/spring-webflow-samples/booking-mvc/src/main/webapp/WEB-INF/login.jsp @@ -1,8 +1,7 @@ <%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %> <%@ taglib prefix="form" uri="http://www.springframework.org/tags/form" %> -<%@ page import="org.springframework.security.web.authentication.AbstractProcessingFilter" %> -<%@ page import="org.springframework.security.web.authentication.AuthenticationProcessingFilter" %> +<%@ page import="org.springframework.security.web.authentication.UsernamePasswordAuthenticationFilter" %> <%@ page import="org.springframework.security.core.AuthenticationException" %>

    Login Required

    @@ -11,7 +10,7 @@
    Your login attempt was not successful, try again.

    - Reason: <%= ((AuthenticationException) session.getAttribute(AbstractProcessingFilter.SPRING_SECURITY_LAST_EXCEPTION_KEY)).getMessage() %> + Reason: <%= ((AuthenticationException) session.getAttribute(UsernamePasswordAuthenticationFilter.SPRING_SECURITY_LAST_EXCEPTION_KEY)).getMessage() %>

    Valid username/passwords are:

    @@ -29,7 +28,7 @@
    - value="<%= session.getAttribute(AuthenticationProcessingFilter.SPRING_SECURITY_LAST_USERNAME_KEY) %>" /> + value="<%= session.getAttribute(UsernamePasswordAuthenticationFilter.SPRING_SECURITY_LAST_USERNAME_KEY) %>" />