diff --git a/spring-webflow-samples/booking-mvc/build.xml b/spring-webflow-samples/booking-mvc/build.xml index 9b9e1520..bc2bd7a7 100755 --- a/spring-webflow-samples/booking-mvc/build.xml +++ b/spring-webflow-samples/booking-mvc/build.xml @@ -1,16 +1,14 @@ - + - - + - \ No newline at end of file diff --git a/spring-webflow-samples/booking-mvc/src/main/java/org/springframework/webflow/samples/booking/flow/booking/BookingActions.java b/spring-webflow-samples/booking-mvc/src/main/java/org/springframework/webflow/samples/booking/flow/booking/BookingActions.java index e0966ed0..687fe914 100644 --- a/spring-webflow-samples/booking-mvc/src/main/java/org/springframework/webflow/samples/booking/flow/booking/BookingActions.java +++ b/spring-webflow-samples/booking-mvc/src/main/java/org/springframework/webflow/samples/booking/flow/booking/BookingActions.java @@ -1,13 +1,15 @@ package org.springframework.webflow.samples.booking.flow.booking; -import java.util.Calendar; +import java.text.SimpleDateFormat; +import java.util.Date; import javax.persistence.EntityManager; -import org.springframework.binding.message.Messages; -import org.springframework.binding.message.Severity; -import org.springframework.webflow.action.MultiAction; -import org.springframework.webflow.execution.Event; +import org.springframework.beans.propertyeditors.CustomDateEditor; +import org.springframework.validation.DataBinder; +import org.springframework.validation.Errors; +import org.springframework.validation.Validator; +import org.springframework.webflow.action.FormAction; import org.springframework.webflow.execution.RequestContext; import org.springframework.webflow.samples.booking.app.Booking; import org.springframework.webflow.samples.booking.app.Hotel; @@ -18,8 +20,20 @@ import org.springframework.webflow.samples.booking.app.User; * definition at the appropriate points. Actions allow an externalized flow definition to delegate out to Java code to * perform processing. */ -public class BookingActions extends MultiAction { +public class BookingActions extends FormAction { + public BookingActions() { + setFormObjectName("booking"); + setValidator(new BookingValidator()); + } + + @Override + protected void initBinder(RequestContext context, DataBinder binder) { + binder.setRequiredFields(new String[] { "checkinDate", "checkoutDate", "creditCard", "creditCardName" }); + binder.registerCustomEditor(Date.class, new CustomDateEditor(new SimpleDateFormat("yyyy-MM-dd"), true)); + } + + @Override /** * Create a new booking object and register it with the flow-managed entity manager. The booking is not actually * flushed to the database at this time; that only occurs when the booking flow reaches its "bookingAuthorized" @@ -31,37 +45,23 @@ public class BookingActions extends MultiAction { * @param context the current flow execution request context * @return success if the booking was created successfully. */ - public Event createBooking(RequestContext context) { + protected Object createFormObject(RequestContext context) throws Exception { Hotel hotel = (Hotel) context.getFlowScope().get("hotel"); User user = (User) context.getConversationScope().get("user"); Booking booking = new Booking(hotel, user); EntityManager em = (EntityManager) context.getFlowScope().get("entityManager"); em.persist(booking); - context.getFlowScope().put("booking", booking); - return success(); + return booking; } - /** - * Perform some custom server-side validation on the flow-scoped Booking object updated by the booking form. - * - * It is expected a future milestone of Spring Web Flow 2.0 will add a Messages abstraction that decouples SWF - * artifacts from environment-specific constructs like the FacesContext. - * @param context the current flow execution request context - * @return success if validation was successful, error if not - */ - public Event validateBooking(RequestContext context) { - Booking booking = (Booking) context.getFlowScope().get("booking"); - Calendar calendar = Calendar.getInstance(); - calendar.add(Calendar.DAY_OF_MONTH, -1); - if (booking.getCheckinDate().before(calendar.getTime())) { - context.getMessageContext().addMessage( - Messages.text("checkinDate", "Check in date must be a future date", Severity.ERROR)); - return error(); - } else if (!booking.getCheckinDate().before(booking.getCheckoutDate())) { - context.getMessageContext().addMessage( - Messages.text("checkoutDate", "Check out date must be later than check in date", Severity.ERROR)); - return error(); + public class BookingValidator implements Validator { + + public boolean supports(Class clazz) { + return Booking.class.equals(clazz); } - return success(); + + public void validate(Object object, Errors errors) { + } + } -} +} \ No newline at end of file diff --git a/spring-webflow-samples/booking-mvc/src/main/java/org/springframework/webflow/samples/booking/flow/main/MainActions.java b/spring-webflow-samples/booking-mvc/src/main/java/org/springframework/webflow/samples/booking/flow/main/MainActions.java index b8e77777..985a9556 100644 --- a/spring-webflow-samples/booking-mvc/src/main/java/org/springframework/webflow/samples/booking/flow/main/MainActions.java +++ b/spring-webflow-samples/booking-mvc/src/main/java/org/springframework/webflow/samples/booking/flow/main/MainActions.java @@ -2,7 +2,8 @@ package org.springframework.webflow.samples.booking.flow.main; import java.util.List; -import org.springframework.webflow.action.MultiAction; +import org.springframework.validation.DataBinder; +import org.springframework.webflow.action.FormAction; import org.springframework.webflow.execution.Event; import org.springframework.webflow.execution.RequestContext; import org.springframework.webflow.samples.booking.app.Booking; @@ -15,7 +16,7 @@ import org.springframework.webflow.samples.booking.app.User; * at the appropriate points. Actions allow an externalized flow definition to delegate out to Java code to perform * processing. */ -public class MainActions extends MultiAction { +public class MainActions extends FormAction { private BookingService bookingService; @@ -56,8 +57,10 @@ public class MainActions extends MultiAction { * @param context the current flow execution request context * @return success */ - public Event findHotels(RequestContext context) { + public Event findHotels(RequestContext context) throws Exception { SearchCriteria search = (SearchCriteria) context.getFlowScope().get("searchCriteria"); + DataBinder binder = createBinder(context, search); + doBind(context, binder); List hotels = bookingService .findHotels(search.getSearchString(), search.getPageSize(), search.getPage()); context.getFlowScope().put("hotels", hotels); diff --git a/spring-webflow-samples/booking-mvc/src/main/java/org/springframework/webflow/samples/booking/flow/main/SearchCriteria.java b/spring-webflow-samples/booking-mvc/src/main/java/org/springframework/webflow/samples/booking/flow/main/SearchCriteria.java index be54bd92..a1c9d1ce 100755 --- a/spring-webflow-samples/booking-mvc/src/main/java/org/springframework/webflow/samples/booking/flow/main/SearchCriteria.java +++ b/spring-webflow-samples/booking-mvc/src/main/java/org/springframework/webflow/samples/booking/flow/main/SearchCriteria.java @@ -54,5 +54,4 @@ public class SearchCriteria implements Serializable { public void setPage(int page) { this.page = page; } - -} +} \ No newline at end of file diff --git a/spring-webflow-samples/booking-mvc/src/main/webapp/WEB-INF/web.xml b/spring-webflow-samples/booking-mvc/src/main/webapp/WEB-INF/web.xml index 472779f2..e47e9f50 100755 --- a/spring-webflow-samples/booking-mvc/src/main/webapp/WEB-INF/web.xml +++ b/spring-webflow-samples/booking-mvc/src/main/webapp/WEB-INF/web.xml @@ -4,6 +4,10 @@ xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd" version="2.4"> + + org.apache.tiles.web.startup.TilesListener + + Spring MVC Dispatcher Servlet diff --git a/spring-webflow-samples/booking-mvc/src/main/webapp/css/screen.css b/spring-webflow-samples/booking-mvc/src/main/webapp/css/screen.css deleted file mode 100755 index c09ea787..00000000 --- a/spring-webflow-samples/booking-mvc/src/main/webapp/css/screen.css +++ /dev/null @@ -1,265 +0,0 @@ -/* Setup defaults since variable in browsers ------------------------------------------------ */ -body, div, dd, dt, dl, img, ul, ol, li, p, h1, h2, h3, h4, h5, form, hr, fieldset { - margin: 0; - padding: 0; -} -/* Element Defaults ------------------------------------------------ */ -html { - height: 100%; - background-color: #9cac7c; -} -img { - border: 0; -} -body { - font-family: Verdana, Arial, Helvetica, sans-serif; - font-size: small; - line-height: 1.25em; - color: #362F2D; - position: relative; - width: 760px; - height: 100%; - margin-left: auto; - margin-right: auto; -} -label { - font-weight: bold; - color: #5E5147; -} -input { - border: 1px solid #C3BBB6; - padding: 4px; - margin: 5px 0; - background: #fff url(../images/input.bg.gif) 0 0 repeat-x; -} -select { - border: 1px solid #C3BBB6; - padding: 4px; - margin: 5px 0; - background: #fff url(../images/input.bg.gif) 0 0 repeat-x; -}ol, ul { - margin: 10px 0px 10px 6px; -} -li { - margin: 10px 12px; -} -fieldset { - border: 0; -} -/* Layout ------------------------------------------------ */ -#document { - padding: 0 1px; - background: #fff url(../images/bg.gif) 0 0 repeat-y; - float: left; - border-bottom: 1px solid #C3BBB6; -} -#header { - float: left; - width: 758px; - height:36px; - background-color: #414f23; -} -#container { - float: left; - width: 758px; - background: url(../images/header.jpg) 0 0 repeat-x; -} -#sidebar { - float: left; - width: 205px; - margin-left: 5px; - margin-top: 185px; - padding-top: 5px; -} -#content { - float: left; - width: 448px; - margin-top: 195px; - padding-top: 5px; - background: #fff url(../images/cnt.bg.gif) 0 0 repeat-x; -} -#footer { - clear: both; - margin-top: 40px; - float: left; - padding: 20px; - border-top: 1px solid #C3BBB6; - background-color: #fff; - width: 718px; - text-align: right; -} -/* General ------------------------------------------------ */ -input[type="submit"], input[type="button"] { - font-weight: bold; - color: #fff; - border: 1px solid #5D1414; - height: 26px; - background: #fff url(../images/btn.bg.gif) 0 0 repeat-x; - border-style: none; -} -.center { - text-align: center; -} -.entry { - clear: both; - padding-top: 10px; -} -.entry .label { - float: left; - padding-top: 10px; - padding-right: 5px; - font-weight: bold; - width: 150px; - text-align: right; -} -.entry .output { - float: left; - width: 250px; - padding-top: 10px; - text-align: left; -} -.entry .input { - float: left; - width: 250px; - text-align: left; -} -/* Sidebar ------------------------------------------------ */ -.notes { - text-align: center; - font-size: small; -} -.errors { - font-size: small; - font-weight: bold; - text-align: center; - color: #600; -} -.errors div { - text-align: left; -} -.errors input { - border: 1px solid #600; -} -.errors ul { - list-style: none; -} -.buttonBox { - text-align: center; - padding: 5px 0; -} -#sidebar p { - font-size: small; - color: #8B7869; - line-height: 150%; - padding-top: 10px; - padding-bottom: 10px; - padding-left: 5px; - padding-right: 5px; -} -#sidebar li { - font-size: small; - color: #8B7869; -} -#sidebar h1 { - line-height: normal; - font-weight: bold; - font-size: small; -} -/* -#sidebar p:hover { - color: #362F2D; -} -*/ -/* Content ------------------------------------------------ */ -#content .section { - float: left; - width: 518px; - padding: 15px 15px 0 10px; -} -#content .section h1 { - font-family: "Trebuchet MS", Arial, sans-serif; - line-height: normal; - font-weight: normal; - font-size: large; -} -#content .section p { - line-height: 150%; - padding: 10px 0; - font-size: small; -} -#content table { - width: 100%; - border: 1px solid #D2C9C4; - border-collapse: collapse; -} -#content table caption { - padding-bottom: 6px; - text-align: left; - font-weight: bold; -} -#content table thead th { - border-left: 1px solid #D2C9C4; - background: #fff url(../images/th.bg.gif) 0 100% repeat-x; - border-bottom: 1px solid #D2C9C4; - padding: 6px; - text-align: left; - font-size: small; -} -#content table tbody td { - border-left: 1px solid #E4DBD5; - padding: 4px; - border-bottom: 1px solid #D2C9C4; - font-size: 8pt; -} -#content dt { - font-weight: bold; - float: left; - width: 33%; -} -#content dd { - padding-left: 10px; - float: left; - width: 66%; -} -#radio table { - border: 0px; -} -#radio table tr td { - border: 0px; - border-left: 0px; - border-bottom: 0px; -} -#content .section .prev { - float: left; - width: 120px; -} -#content .section .next { - float: left; -} -/* Header ------------------------------------------------ */ -#title { - float: left; - padding: 10px 0 6px 15px; - color: #e9efdb; -} -#status { - color: #e9efdb; - float: right; - font-family: Verdana, Arial, Helvetica, sans-serif; - font-weight: bold; - font-size: x-small; - text-align: right; - padding-top: 14px; - padding-right: 15px; -} -#status a { - color: #e9efdb; - text-decoration: none; -} diff --git a/spring-webflow-samples/booking-mvc/src/main/webapp/flow/booking/booking.xml b/spring-webflow-samples/booking-mvc/src/main/webapp/flow/booking/booking.xml index 78b3de0e..b209baac 100755 --- a/spring-webflow-samples/booking-mvc/src/main/webapp/flow/booking/booking.xml +++ b/spring-webflow-samples/booking-mvc/src/main/webapp/flow/booking/booking.xml @@ -2,7 +2,7 @@ + http://www.springframework.org/schema/webflow/spring-webflow-2.0.xsd"> @@ -27,18 +27,16 @@ - + - - - - - + + + - + diff --git a/spring-webflow-samples/booking-mvc/src/main/webapp/flow/booking/bookingForm.jsp b/spring-webflow-samples/booking-mvc/src/main/webapp/flow/booking/bookingForm.jsp index 91bf8226..df381eb6 100755 --- a/spring-webflow-samples/booking-mvc/src/main/webapp/flow/booking/bookingForm.jsp +++ b/spring-webflow-samples/booking-mvc/src/main/webapp/flow/booking/bookingForm.jsp @@ -1,4 +1,7 @@ +<%@ 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" %> @@ -8,146 +11,124 @@
- - + +
-
+
Name:
-
#{hotel.name}
+
${hotel.name}
-
+
Address:
-
#{hotel.address}
+
${hotel.address}
-
+
City, State:
-
#{hotel.city}, #{hotel.state}
+
${hotel.city}, ${hotel.state}
-
+
Zip:
-
#{hotel.zip}
+
${hotel.zip}
-
+
Country:
-
#{hotel.country}
+
${hotel.country}
-
+
Nightly rate:
- - - + ${status.value}
-
+
- Check In Date: +
- - - - - + +
-
+
- Check Out Date: +
- - - - - + +
-
+
- Room Preference: +
- - - - - + + + + +
-
+
- Smoking Preference: +
- - - - + +
-
+
- Credit Card #: +
- - - + +
-
+
- Credit Card Name: +
- - - + +
-
+
- Credit Card Expiry: +
- - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + +
-
- -
-
-
 
-
- - -   - -
+
+   +  
-
+
diff --git a/spring-webflow-samples/booking-mvc/src/main/webapp/flow/booking/confirmBooking.jsp b/spring-webflow-samples/booking-mvc/src/main/webapp/flow/booking/confirmBooking.jsp index 1c439e80..f627aa43 100755 --- a/spring-webflow-samples/booking-mvc/src/main/webapp/flow/booking/confirmBooking.jsp +++ b/spring-webflow-samples/booking-mvc/src/main/webapp/flow/booking/confirmBooking.jsp @@ -1,4 +1,7 @@ +<%@ 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" %> @@ -8,60 +11,54 @@
- +
-
+
Name:
-
#{hotel.name}
+
${hotel.name}
-
+
Address:
-
#{hotel.address}
+
${hotel.address}
-
+
City, State:
-
#{hotel.city}, #{hotel.state}
+
${hotel.city}, ${hotel.state}
-
+
Zip:
-
#{hotel.zip}
+
${hotel.zip}
-
+
Country:
-
#{hotel.country}
+
${hotel.country}
-
+
Total payment:
-
- - - +
+ ${status.value}
-
+
Check In Date:
-
+
${status.value}
-
+
Check Out Date:
-
+
${status.value}
-
+
Credit Card #:
-
#{booking.creditCard}
+
${booking.creditCard}
-
-
 
-
-   -   - -
+
+   +   +  
-
+
-
+
\ No newline at end of file diff --git a/spring-webflow-samples/booking-mvc/src/main/webapp/flow/booking/hotelDetails.jsp b/spring-webflow-samples/booking-mvc/src/main/webapp/flow/booking/hotelDetails.jsp index 1cac7c6f..0102febe 100755 --- a/spring-webflow-samples/booking-mvc/src/main/webapp/flow/booking/hotelDetails.jsp +++ b/spring-webflow-samples/booking-mvc/src/main/webapp/flow/booking/hotelDetails.jsp @@ -1,4 +1,7 @@ +<%@ 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" %> @@ -8,48 +11,45 @@
-
-
Name:
-
#{hotel.name}
-
-
-
Address:
-
#{hotel.address}
-
-
-
City:
-
#{hotel.city}
-
-
-
State:
-
#{hotel.state}
-
-
-
Zip:
-
#{hotel.zip}
-
-
-
Country:
-
#{hotel.country}
-
-
-
Nightly rate:
-
- - - -
-
-
- -
- -
-   - + +
+
+
Name:
+
${hotel.name}
+
+
+
Address:
+
${hotel.address}
+
+
+
City:
+
${hotel.city}
+
+
+
State:
+
${hotel.state}
+
+
+
Zip:
+
${hotel.zip}
+
+
+
Country:
+
${hotel.country}
+
+
+
Nightly rate:
+
+ ${status.value} +
+
+
+   +   +
- +
- +
\ No newline at end of file diff --git a/spring-webflow-samples/booking-mvc/src/main/webapp/flow/main/main.jsp b/spring-webflow-samples/booking-mvc/src/main/webapp/flow/main/main.jsp index 67f20c9a..8a979a26 100755 --- a/spring-webflow-samples/booking-mvc/src/main/webapp/flow/main/main.jsp +++ b/spring-webflow-samples/booking-mvc/src/main/webapp/flow/main/main.jsp @@ -8,7 +8,7 @@
- +

Search Hotels

@@ -19,15 +19,11 @@ - - +
- - No Hotels Found - @@ -38,18 +34,14 @@ - + - - - - + + + + @@ -62,10 +54,6 @@
- - No Bookings Found - -
#{hotel.name}#{hotel.address}#{hotel.city}, #{hotel.state}, #{hotel.country}#{hotel.zip}${hotel.name}${hotel.address}${hotel.city}, ${hotel.state}, ${hotel.country}${hotel.zip} - - - - - View Hotel + View Hotel
@@ -79,20 +67,16 @@ - + - - - - - - + + + + + + diff --git a/spring-webflow-samples/booking-mvc/src/main/webapp/flow/main/main.xml b/spring-webflow-samples/booking-mvc/src/main/webapp/flow/main/main.xml index b103e0e2..b0dbba02 100755 --- a/spring-webflow-samples/booking-mvc/src/main/webapp/flow/main/main.xml +++ b/spring-webflow-samples/booking-mvc/src/main/webapp/flow/main/main.xml @@ -2,7 +2,7 @@ + http://www.springframework.org/schema/webflow/spring-webflow-2.0.xsd"> diff --git a/spring-webflow-samples/booking-mvc/src/main/webapp/template.jsp b/spring-webflow-samples/booking-mvc/src/main/webapp/template.jsp index 4eeda536..8f6a16c0 100644 --- a/spring-webflow-samples/booking-mvc/src/main/webapp/template.jsp +++ b/spring-webflow-samples/booking-mvc/src/main/webapp/template.jsp @@ -5,25 +5,35 @@ Spring Faces: Hotel Booking Sample Application - - + - - -
-
#{booking.hotel.name}#{booking.hotel.address}#{booking.hotel.city}, #{booking.hotel.state}#{booking.checkinDate}#{booking.checkoutDate}#{booking.id}${booking.hotel.name}${booking.hotel.address}${booking.hotel.city}, ${booking.hotel.state}${booking.checkinDate}${booking.checkoutDate}${booking.id} - - - - - Cancel + Cancel