diff --git a/spring-webflow-samples/booking-faces/src/main/java/org/springframework/webflow/samples/booking/Booking.java b/spring-webflow-samples/booking-faces/src/main/java/org/springframework/webflow/samples/booking/Booking.java index 3dca77b6..679cd04c 100755 --- a/spring-webflow-samples/booking-faces/src/main/java/org/springframework/webflow/samples/booking/Booking.java +++ b/spring-webflow-samples/booking-faces/src/main/java/org/springframework/webflow/samples/booking/Booking.java @@ -178,20 +178,20 @@ public class Booking implements Serializable { this.creditCardExpiryYear = creditCardExpiryYear; } - public boolean validateEnterBookingDetails(MessageContext context) { - Calendar calendar = Calendar.getInstance(); - calendar.add(Calendar.DAY_OF_MONTH, -1); - boolean valid = true; - if (checkinDate.before(calendar.getTime())) { + public void validateEnterBookingDetails(MessageContext context) { + if (checkinDate.before(today())) { context.addMessage(new MessageBuilder().error().source("checkinDate").defaultText( - "Check in date must be a future date").build()); - valid = false; + "The Check In Date must be a future date").build()); } else if (!checkinDate.before(checkoutDate)) { context.addMessage(new MessageBuilder().error().source("checkoutDate").defaultText( - "Check out date must be later than check in date").build()); - valid = false; + "The Check Out Date must be later than the Check In Date").build()); } - return valid; + } + + private Date today() { + Calendar calendar = Calendar.getInstance(); + calendar.add(Calendar.DAY_OF_MONTH, -1); + return calendar.getTime(); } @Override diff --git a/spring-webflow-samples/booking-mvc/src/main/java/org/springframework/webflow/samples/booking/Booking.java b/spring-webflow-samples/booking-mvc/src/main/java/org/springframework/webflow/samples/booking/Booking.java index c69681e4..0a95fd3b 100755 --- a/spring-webflow-samples/booking-mvc/src/main/java/org/springframework/webflow/samples/booking/Booking.java +++ b/spring-webflow-samples/booking-mvc/src/main/java/org/springframework/webflow/samples/booking/Booking.java @@ -176,20 +176,20 @@ public class Booking implements Serializable { this.creditCardExpiryYear = creditCardExpiryYear; } - public boolean validateEnterBookingDetails(MessageContext context) { + public void validateEnterBookingDetails(MessageContext context) { + if (checkinDate.before(today())) { + context.addMessage(new MessageBuilder().error().source("checkinDate").code("checkinDate.beforeToday") + .build()); + } else if (checkoutDate.before(checkinDate)) { + context.addMessage(new MessageBuilder().error().source("checkoutDate").code( + "checkoutDate.beforeCheckinDate").build()); + } + } + + private Date today() { Calendar calendar = Calendar.getInstance(); calendar.add(Calendar.DAY_OF_MONTH, -1); - boolean valid = true; - if (checkinDate.before(calendar.getTime())) { - context.addMessage(new MessageBuilder().error().source("checkinDate").defaultText( - "Check in date must be a future date").build()); - valid = false; - } else if (!checkinDate.before(checkoutDate)) { - context.addMessage(new MessageBuilder().error().source("checkoutDate").defaultText( - "Check out date must be later than check in date").build()); - valid = false; - } - return valid; + return calendar.getTime(); } @Override diff --git a/spring-webflow-samples/booking-mvc/src/main/webapp/WEB-INF/hotels/booking/messages.properties b/spring-webflow-samples/booking-mvc/src/main/webapp/WEB-INF/hotels/booking/messages.properties index 692328a7..5b582e8b 100644 --- a/spring-webflow-samples/booking-mvc/src/main/webapp/WEB-INF/hotels/booking/messages.properties +++ b/spring-webflow-samples/booking-mvc/src/main/webapp/WEB-INF/hotels/booking/messages.properties @@ -1,2 +1,4 @@ +checkinDate.beforeToday=The Check In Date must be a future date +checkoutDate.beforeCheckinDate=The Check Out date must be later than the Check In Date booking.checkinDate.typeMismatch=The Check In Date must be in the format dd/mm/yy booking.checkoutDate.typeMismatch=The Check Out Date must be in the format dd/mm/yy \ No newline at end of file