From 266ed30fec473ef80c4c6a4ff7d37686ad2bc03f Mon Sep 17 00:00:00 2001 From: Scott Andrews Date: Wed, 5 Mar 2008 20:57:57 +0000 Subject: [PATCH] Updated to work with Web Flow 2.0. Added Spring Security integration. --- spring-webflow-samples/booking-mvc/.classpath | 2 + .../org.eclipse.wst.common.component | 2 + .../booking-mvc/.springBeans | 19 +-- spring-webflow-samples/booking-mvc/ivy.xml | 23 +-- .../samples/booking/{app => }/Booking.java | 13 +- .../booking/{app => }/BookingService.java | 15 +- .../samples/booking/BookingValidator.java | 31 ++++ .../samples/booking/{app => }/Hotel.java | 6 +- .../booking/{app => }/JpaBookingService.java | 29 ++-- .../samples/booking/PropertyEditors.java | 16 ++ .../{flow/main => }/SearchCriteria.java | 3 +- .../samples/booking/{app => }/User.java | 2 +- .../booking/flow/booking/BookingActions.java | 72 --------- .../booking/flow/main/MainActions.java | 69 -------- .../META-INF/persistence.xml | 6 +- .../src/main/{java => resources}/import.sql | 4 +- .../booking-mvc/src/main/resources/log4j.xml | 44 ++++++ .../config/application-layer-config.xml | 44 ------ .../WEB-INF/config/web-application-config.xml | 60 ------- .../src/main/webapp/WEB-INF/intro.jsp | 28 ++++ .../layouts/standard.jsp} | 23 ++- .../src/main/webapp/WEB-INF/login.jsp | 62 ++++++++ .../main/webapp/WEB-INF/logout-success.jsp | 16 ++ .../webapp/WEB-INF/web-application-config.xml | 148 ++++++++++++++++++ .../src/main/webapp/WEB-INF/web.xml | 45 +++++- .../src/main/webapp/css/booking.css | 5 + .../webapp/flow/booking/booking-beans.xml | 10 -- .../src/main/webapp/flow/booking/booking.xml | 62 -------- .../main/webapp/flow/booking/bookingForm.jsp | 135 ---------------- .../webapp/flow/booking/confirmBooking.jsp | 64 -------- .../main/webapp/flow/booking/hotelDetails.jsp | 55 ------- .../src/main/webapp/flow/main/main-beans.xml | 12 -- .../src/main/webapp/flow/main/main.jsp | 91 ----------- .../src/main/webapp/flow/main/main.xml | 55 ------- .../booking-mvc/src/main/webapp/intro.jsp | 67 -------- 35 files changed, 483 insertions(+), 855 deletions(-) rename spring-webflow-samples/booking-mvc/src/main/java/org/springframework/webflow/samples/booking/{app => }/Booking.java (93%) rename spring-webflow-samples/booking-mvc/src/main/java/org/springframework/webflow/samples/booking/{app => }/BookingService.java (70%) create mode 100644 spring-webflow-samples/booking-mvc/src/main/java/org/springframework/webflow/samples/booking/BookingValidator.java rename spring-webflow-samples/booking-mvc/src/main/java/org/springframework/webflow/samples/booking/{app => }/Hotel.java (92%) rename spring-webflow-samples/booking-mvc/src/main/java/org/springframework/webflow/samples/booking/{app => }/JpaBookingService.java (55%) create mode 100644 spring-webflow-samples/booking-mvc/src/main/java/org/springframework/webflow/samples/booking/PropertyEditors.java rename spring-webflow-samples/booking-mvc/src/main/java/org/springframework/webflow/samples/booking/{flow/main => }/SearchCriteria.java (91%) rename spring-webflow-samples/booking-mvc/src/main/java/org/springframework/webflow/samples/booking/{app => }/User.java (89%) delete mode 100644 spring-webflow-samples/booking-mvc/src/main/java/org/springframework/webflow/samples/booking/flow/booking/BookingActions.java delete mode 100644 spring-webflow-samples/booking-mvc/src/main/java/org/springframework/webflow/samples/booking/flow/main/MainActions.java rename spring-webflow-samples/booking-mvc/src/main/{java => resources}/META-INF/persistence.xml (78%) rename spring-webflow-samples/booking-mvc/src/main/{java => resources}/import.sql (94%) create mode 100644 spring-webflow-samples/booking-mvc/src/main/resources/log4j.xml delete mode 100755 spring-webflow-samples/booking-mvc/src/main/webapp/WEB-INF/config/application-layer-config.xml delete mode 100755 spring-webflow-samples/booking-mvc/src/main/webapp/WEB-INF/config/web-application-config.xml create mode 100755 spring-webflow-samples/booking-mvc/src/main/webapp/WEB-INF/intro.jsp rename spring-webflow-samples/booking-mvc/src/main/webapp/{template.jsp => WEB-INF/layouts/standard.jsp} (64%) create mode 100755 spring-webflow-samples/booking-mvc/src/main/webapp/WEB-INF/login.jsp create mode 100755 spring-webflow-samples/booking-mvc/src/main/webapp/WEB-INF/logout-success.jsp create mode 100755 spring-webflow-samples/booking-mvc/src/main/webapp/WEB-INF/web-application-config.xml delete mode 100755 spring-webflow-samples/booking-mvc/src/main/webapp/flow/booking/booking-beans.xml delete mode 100755 spring-webflow-samples/booking-mvc/src/main/webapp/flow/booking/booking.xml delete mode 100755 spring-webflow-samples/booking-mvc/src/main/webapp/flow/booking/bookingForm.jsp delete mode 100755 spring-webflow-samples/booking-mvc/src/main/webapp/flow/booking/confirmBooking.jsp delete mode 100755 spring-webflow-samples/booking-mvc/src/main/webapp/flow/booking/hotelDetails.jsp delete mode 100755 spring-webflow-samples/booking-mvc/src/main/webapp/flow/main/main-beans.xml delete mode 100755 spring-webflow-samples/booking-mvc/src/main/webapp/flow/main/main.jsp delete mode 100755 spring-webflow-samples/booking-mvc/src/main/webapp/flow/main/main.xml delete mode 100755 spring-webflow-samples/booking-mvc/src/main/webapp/intro.jsp diff --git a/spring-webflow-samples/booking-mvc/.classpath b/spring-webflow-samples/booking-mvc/.classpath index e7394167..5e974b0f 100755 --- a/spring-webflow-samples/booking-mvc/.classpath +++ b/spring-webflow-samples/booking-mvc/.classpath @@ -1,7 +1,9 @@ + + diff --git a/spring-webflow-samples/booking-mvc/.settings/org.eclipse.wst.common.component b/spring-webflow-samples/booking-mvc/.settings/org.eclipse.wst.common.component index a82589ae..a657fe76 100755 --- a/spring-webflow-samples/booking-mvc/.settings/org.eclipse.wst.common.component +++ b/spring-webflow-samples/booking-mvc/.settings/org.eclipse.wst.common.component @@ -4,6 +4,8 @@ + + diff --git a/spring-webflow-samples/booking-mvc/.springBeans b/spring-webflow-samples/booking-mvc/.springBeans index 7df5daff..72dab5ab 100755 --- a/spring-webflow-samples/booking-mvc/.springBeans +++ b/spring-webflow-samples/booking-mvc/.springBeans @@ -1,13 +1,12 @@ - - xml - + 1 + + + + + - src/main/webapp/WEB-INF/config/application-layer-config.xml - src/main/webapp/WEB-INF/config/web-application-config.xml - src/main/webapp/flow/main/main-beans.xml - src/main/webapp/flow/booking/booking-beans.xml @@ -15,8 +14,6 @@ true false - src/main/webapp/WEB-INF/config/application-layer-config.xml - src/main/webapp/WEB-INF/config/web-application-config.xml @@ -24,8 +21,6 @@ true false - src/main/webapp/flow/booking/booking-beans.xml - src/main/webapp/WEB-INF/config/application-layer-config.xml @@ -33,8 +28,6 @@ true false - src/main/webapp/flow/main/main-beans.xml - src/main/webapp/WEB-INF/config/application-layer-config.xml diff --git a/spring-webflow-samples/booking-mvc/ivy.xml b/spring-webflow-samples/booking-mvc/ivy.xml index 80198be0..7118a60f 100755 --- a/spring-webflow-samples/booking-mvc/ivy.xml +++ b/spring-webflow-samples/booking-mvc/ivy.xml @@ -11,24 +11,27 @@ - + - - + + + - - - - + + + + + + - - + + @@ -39,7 +42,7 @@ - + \ No newline at end of file diff --git a/spring-webflow-samples/booking-mvc/src/main/java/org/springframework/webflow/samples/booking/app/Booking.java b/spring-webflow-samples/booking-mvc/src/main/java/org/springframework/webflow/samples/booking/Booking.java similarity index 93% rename from spring-webflow-samples/booking-mvc/src/main/java/org/springframework/webflow/samples/booking/app/Booking.java rename to spring-webflow-samples/booking-mvc/src/main/java/org/springframework/webflow/samples/booking/Booking.java index 22edfe95..e44bc8ab 100755 --- a/spring-webflow-samples/booking-mvc/src/main/java/org/springframework/webflow/samples/booking/app/Booking.java +++ b/spring-webflow-samples/booking-mvc/src/main/java/org/springframework/webflow/samples/booking/Booking.java @@ -1,4 +1,4 @@ -package org.springframework.webflow.samples.booking.app; +package org.springframework.webflow.samples.booking; import java.io.Serializable; import java.math.BigDecimal; @@ -44,17 +44,18 @@ public class Booking implements Serializable { private int beds; public Booking() { - } - - public Booking(Hotel hotel, User user) { - this.hotel = hotel; - this.user = user; Calendar calendar = Calendar.getInstance(); setCheckinDate(calendar.getTime()); calendar.add(Calendar.DAY_OF_MONTH, 1); setCheckoutDate(calendar.getTime()); } + public Booking(Hotel hotel, User user) { + this(); + this.hotel = hotel; + this.user = user; + } + @Transient public BigDecimal getTotal() { return hotel.getPrice().multiply(new BigDecimal(getNights())); diff --git a/spring-webflow-samples/booking-mvc/src/main/java/org/springframework/webflow/samples/booking/app/BookingService.java b/spring-webflow-samples/booking-mvc/src/main/java/org/springframework/webflow/samples/booking/BookingService.java similarity index 70% rename from spring-webflow-samples/booking-mvc/src/main/java/org/springframework/webflow/samples/booking/app/BookingService.java rename to spring-webflow-samples/booking-mvc/src/main/java/org/springframework/webflow/samples/booking/BookingService.java index 80b3b023..5d109fcf 100755 --- a/spring-webflow-samples/booking-mvc/src/main/java/org/springframework/webflow/samples/booking/app/BookingService.java +++ b/spring-webflow-samples/booking-mvc/src/main/java/org/springframework/webflow/samples/booking/BookingService.java @@ -1,4 +1,4 @@ -package org.springframework.webflow.samples.booking.app; +package org.springframework.webflow.samples.booking; import java.util.List; @@ -17,12 +17,10 @@ public interface BookingService { /** * Find hotels available for booking by some criteria. - * @param searchString the search query string to filter hotels by name - * @param pageSize the page size - * @param page the current page + * @param searchCriteria the search criteria * @return a list of hotels not exceeding the page size */ - public List findHotels(String searchString, int pageSize, int page); + public List findHotels(SearchCriteria searchCriteria); /** * Find hotels by their identifier. @@ -36,4 +34,11 @@ public interface BookingService { * @param id the booking id */ public void cancelBooking(Long id); + + /** + * Lookup a user based on their username + * @param username the user's username + * @return the user + */ + public User findUser(String username); } diff --git a/spring-webflow-samples/booking-mvc/src/main/java/org/springframework/webflow/samples/booking/BookingValidator.java b/spring-webflow-samples/booking-mvc/src/main/java/org/springframework/webflow/samples/booking/BookingValidator.java new file mode 100644 index 00000000..f0977e17 --- /dev/null +++ b/spring-webflow-samples/booking-mvc/src/main/java/org/springframework/webflow/samples/booking/BookingValidator.java @@ -0,0 +1,31 @@ +package org.springframework.webflow.samples.booking; + +import java.util.Calendar; + +import org.springframework.validation.Errors; +import org.springframework.validation.Validator; + +public class BookingValidator implements Validator { + + public boolean supports(Class clazz) { + return Booking.class.equals(clazz); + } + + public void validate(Object obj, Errors errors) { + Booking booking = (Booking) obj; + Calendar calendar = Calendar.getInstance(); + calendar.add(Calendar.DAY_OF_MONTH, -1); + if (booking.getCreditCard() == null || "".equals(booking.getCreditCard())) { + errors.rejectValue("creditCard", null, "Credit card number must be provided"); + } + if (booking.getCreditCardName() == null || "".equals(booking.getCreditCardName())) { + errors.rejectValue("creditCardName", null, "Credit card name must be provided"); + } + if (booking.getCheckinDate() == null || booking.getCheckinDate().before(calendar.getTime())) { + errors.rejectValue("checkinDate", null, "Check in date must be a future date"); + } else if (booking.getCheckoutDate() == null || !booking.getCheckinDate().before(booking.getCheckoutDate())) { + errors.rejectValue("checkoutDate", null, "Check out date must be later than check in date"); + } + } + +} diff --git a/spring-webflow-samples/booking-mvc/src/main/java/org/springframework/webflow/samples/booking/app/Hotel.java b/spring-webflow-samples/booking-mvc/src/main/java/org/springframework/webflow/samples/booking/Hotel.java similarity index 92% rename from spring-webflow-samples/booking-mvc/src/main/java/org/springframework/webflow/samples/booking/app/Hotel.java rename to spring-webflow-samples/booking-mvc/src/main/java/org/springframework/webflow/samples/booking/Hotel.java index bef830c5..99719e50 100755 --- a/spring-webflow-samples/booking-mvc/src/main/java/org/springframework/webflow/samples/booking/app/Hotel.java +++ b/spring-webflow-samples/booking-mvc/src/main/java/org/springframework/webflow/samples/booking/Hotel.java @@ -1,4 +1,4 @@ -package org.springframework.webflow.samples.booking.app; +package org.springframework.webflow.samples.booking; import java.io.Serializable; import java.math.BigDecimal; @@ -96,6 +96,10 @@ public class Hotel implements Serializable { this.price = price; } + public Booking createBooking(User user) { + return new Booking(this, user); + } + @Override public String toString() { return "Hotel(" + name + "," + address + "," + city + "," + zip + ")"; diff --git a/spring-webflow-samples/booking-mvc/src/main/java/org/springframework/webflow/samples/booking/app/JpaBookingService.java b/spring-webflow-samples/booking-mvc/src/main/java/org/springframework/webflow/samples/booking/JpaBookingService.java similarity index 55% rename from spring-webflow-samples/booking-mvc/src/main/java/org/springframework/webflow/samples/booking/app/JpaBookingService.java rename to spring-webflow-samples/booking-mvc/src/main/java/org/springframework/webflow/samples/booking/JpaBookingService.java index a4a92f19..a29348d6 100755 --- a/spring-webflow-samples/booking-mvc/src/main/java/org/springframework/webflow/samples/booking/app/JpaBookingService.java +++ b/spring-webflow-samples/booking-mvc/src/main/java/org/springframework/webflow/samples/booking/JpaBookingService.java @@ -1,4 +1,4 @@ -package org.springframework.webflow.samples.booking.app; +package org.springframework.webflow.samples.booking; import java.util.List; @@ -27,19 +27,24 @@ public class JpaBookingService implements BookingService { @Transactional(readOnly = true) @SuppressWarnings("unchecked") public List findBookings(String username) { - return em.createQuery("select b from Booking b where b.user.username = :username order by b.checkinDate") - .setParameter("username", username).getResultList(); + if (username != null) { + return em.createQuery("select b from Booking b where b.user.username = :username order by b.checkinDate") + .setParameter("username", username).getResultList(); + } else { + return null; + } } @Transactional(readOnly = true) @SuppressWarnings("unchecked") - public List findHotels(String searchString, int pageSize, int page) { - String pattern = !StringUtils.hasText(searchString) ? "'%'" : "'%" - + searchString.toLowerCase().replace('*', '%') + "%'"; + public List findHotels(SearchCriteria search) { + String pattern = !StringUtils.hasText(search.getSearchString()) ? "%" : "%" + + search.getSearchString().toLowerCase().replace('*', '%') + "%"; return em.createQuery( - "select h from Hotel h where lower(h.name) like " + pattern + " or lower(h.city) like " + pattern - + " or lower(h.zip) like " + pattern + " or lower(h.address) like " + pattern).setMaxResults( - pageSize).setFirstResult(page * pageSize).getResultList(); + "select h from Hotel h where lower(h.name) like :pattern or lower(h.city) like :pattern " + + "or lower(h.zip) like :pattern or lower(h.address) like :pattern").setParameter("pattern", + pattern).setMaxResults(search.getPageSize()).setFirstResult(search.getPage() * search.getPageSize()) + .getResultList(); } @Transactional(readOnly = true) @@ -55,4 +60,10 @@ public class JpaBookingService implements BookingService { em.remove(booking); } } + + @Transactional(readOnly = true) + public User findUser(String username) { + return (User) em.createQuery("select u from User u where u.username = :username").setParameter("username", + username).getSingleResult(); + } } \ No newline at end of file diff --git a/spring-webflow-samples/booking-mvc/src/main/java/org/springframework/webflow/samples/booking/PropertyEditors.java b/spring-webflow-samples/booking-mvc/src/main/java/org/springframework/webflow/samples/booking/PropertyEditors.java new file mode 100644 index 00000000..a6b49c41 --- /dev/null +++ b/spring-webflow-samples/booking-mvc/src/main/java/org/springframework/webflow/samples/booking/PropertyEditors.java @@ -0,0 +1,16 @@ +package org.springframework.webflow.samples.booking; + +import java.text.SimpleDateFormat; +import java.util.Date; + +import org.springframework.beans.PropertyEditorRegistrar; +import org.springframework.beans.PropertyEditorRegistry; +import org.springframework.beans.propertyeditors.CustomDateEditor; + +public class PropertyEditors implements PropertyEditorRegistrar { + + public void registerCustomEditors(PropertyEditorRegistry registry) { + registry.registerCustomEditor(Date.class, new CustomDateEditor(new SimpleDateFormat("yyyy-MM-dd"), true)); + } + +} 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/SearchCriteria.java similarity index 91% rename from spring-webflow-samples/booking-mvc/src/main/java/org/springframework/webflow/samples/booking/flow/main/SearchCriteria.java rename to spring-webflow-samples/booking-mvc/src/main/java/org/springframework/webflow/samples/booking/SearchCriteria.java index a1c9d1ce..0db814b3 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/SearchCriteria.java @@ -1,8 +1,7 @@ -package org.springframework.webflow.samples.booking.flow.main; +package org.springframework.webflow.samples.booking; import java.io.Serializable; -import org.springframework.webflow.samples.booking.app.BookingService; /** * A backing bean for the main hotel search form. Encapsulates the criteria needed to perform a hotel search. diff --git a/spring-webflow-samples/booking-mvc/src/main/java/org/springframework/webflow/samples/booking/app/User.java b/spring-webflow-samples/booking-mvc/src/main/java/org/springframework/webflow/samples/booking/User.java similarity index 89% rename from spring-webflow-samples/booking-mvc/src/main/java/org/springframework/webflow/samples/booking/app/User.java rename to spring-webflow-samples/booking-mvc/src/main/java/org/springframework/webflow/samples/booking/User.java index ee436b92..55213ad0 100755 --- a/spring-webflow-samples/booking-mvc/src/main/java/org/springframework/webflow/samples/booking/app/User.java +++ b/spring-webflow-samples/booking-mvc/src/main/java/org/springframework/webflow/samples/booking/User.java @@ -1,4 +1,4 @@ -package org.springframework.webflow.samples.booking.app; +package org.springframework.webflow.samples.booking; import java.io.Serializable; 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 deleted file mode 100644 index d779d4a1..00000000 --- a/spring-webflow-samples/booking-mvc/src/main/java/org/springframework/webflow/samples/booking/flow/booking/BookingActions.java +++ /dev/null @@ -1,72 +0,0 @@ -package org.springframework.webflow.samples.booking.flow.booking; - -import java.text.SimpleDateFormat; -import java.util.Date; - -import javax.persistence.EntityManager; - -import org.springframework.beans.PropertyEditorRegistry; -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; -import org.springframework.webflow.samples.booking.app.User; - -/** - * Actions invoked by the booking flow. These actions are extensions of the flow definition, called by the flow - * definition at the appropriate points. Actions allow an externalized flow definition to delegate out to Java code to - * perform processing. - */ -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" }); - } - - @Override - protected void registerPropertyEditors(PropertyEditorRegistry registry) { - registry.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" - * end-state, which is a "commit" state. - * - * It is expected a future milestone of Spring Web Flow 2.0 will support Flows being defined fully in Java and - * Groovy, allowing logic like this to be defined with the flow definition and without the attribute lookup code you - * see here. - * @param context the current flow execution request context - * @return success if the booking was created successfully. - */ - 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); - return booking; - } - - public class BookingValidator implements Validator { - - public boolean supports(Class clazz) { - return Booking.class.equals(clazz); - } - - 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 deleted file mode 100644 index 985a9556..00000000 --- a/spring-webflow-samples/booking-mvc/src/main/java/org/springframework/webflow/samples/booking/flow/main/MainActions.java +++ /dev/null @@ -1,69 +0,0 @@ -package org.springframework.webflow.samples.booking.flow.main; - -import java.util.List; - -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; -import org.springframework.webflow.samples.booking.app.BookingService; -import org.springframework.webflow.samples.booking.app.Hotel; -import org.springframework.webflow.samples.booking.app.User; - -/** - * Actions invoked by the main flow. These actions are extensions of the flow definition, called by the flow definition - * at the appropriate points. Actions allow an externalized flow definition to delegate out to Java code to perform - * processing. - */ -public class MainActions extends FormAction { - - private BookingService bookingService; - - /** - * Constructs a new multi-action for the main flow that will delegate to the provided booking service - * @param bookingService the booking service - */ - public MainActions(BookingService bookingService) { - this.bookingService = bookingService; - } - - /** - * Simply put a dummy user in conversation scope to simulate a user login. In the future this sample may add user - * authentication support. - * @param context the current flow execution request context - * @return success - */ - public Event initCurrentUser(RequestContext context) { - User user = new User("springer", "springrocks", "Springer"); - context.getConversationScope().put("user", user); - return success(); - } - - /** - * Find all active bookings made by the current user. - * @param context the current flow execution request context - * @return success - */ - public Event findCurrentUserBookings(RequestContext context) { - User user = (User) context.getConversationScope().get("user"); - List bookings = bookingService.findBookings(user.getUsername()); - context.getFlowScope().put("bookings", bookings); - return success(); - } - - /** - * Find all hotels that meet the current search criteria in flow scope. - * @param context the current flow execution request context - * @return success - */ - 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); - return success(); - } -} diff --git a/spring-webflow-samples/booking-mvc/src/main/java/META-INF/persistence.xml b/spring-webflow-samples/booking-mvc/src/main/resources/META-INF/persistence.xml similarity index 78% rename from spring-webflow-samples/booking-mvc/src/main/java/META-INF/persistence.xml rename to spring-webflow-samples/booking-mvc/src/main/resources/META-INF/persistence.xml index 4ad486f6..f4e3d6a7 100755 --- a/spring-webflow-samples/booking-mvc/src/main/java/META-INF/persistence.xml +++ b/spring-webflow-samples/booking-mvc/src/main/resources/META-INF/persistence.xml @@ -5,9 +5,9 @@ version="1.0"> org.hibernate.ejb.HibernatePersistence - org.springframework.webflow.samples.booking.app.User - org.springframework.webflow.samples.booking.app.Booking - org.springframework.webflow.samples.booking.app.Hotel + org.springframework.webflow.samples.booking.User + org.springframework.webflow.samples.booking.Booking + org.springframework.webflow.samples.booking.Hotel diff --git a/spring-webflow-samples/booking-mvc/src/main/java/import.sql b/spring-webflow-samples/booking-mvc/src/main/resources/import.sql similarity index 94% rename from spring-webflow-samples/booking-mvc/src/main/java/import.sql rename to spring-webflow-samples/booking-mvc/src/main/resources/import.sql index 7c57d9d0..cd3a125b 100755 --- a/spring-webflow-samples/booking-mvc/src/main/java/import.sql +++ b/spring-webflow-samples/booking-mvc/src/main/resources/import.sql @@ -1,4 +1,6 @@ -insert into Customer (username, password, name) values ('springer', 'springrocks', 'Springer') +insert into Customer (username, name) values ('rod', 'Rod') +insert into Customer (username, name) values ('dianne', 'Dianne') +insert into Customer (username, name) values ('scott', 'Scott') insert into Hotel (id, price, name, address, city, state, zip, country) values (1, 199, 'Westin Diplomat', '3555 S. Ocean Drive', 'Hollywood', 'FL', '33019', 'USA') insert into Hotel (id, price, name, address, city, state, zip, country) values (2, 120, 'Marriott Courtyard', 'Tower Place, Buckhead', 'Atlanta', 'GA', '30305', 'USA') insert into Hotel (id, price, name, address, city, state, zip, country) values (3, 180, 'Doubletree', 'Tower Place, Buckhead', 'Atlanta', 'GA', '30305', 'USA') diff --git a/spring-webflow-samples/booking-mvc/src/main/resources/log4j.xml b/spring-webflow-samples/booking-mvc/src/main/resources/log4j.xml new file mode 100644 index 00000000..b50d654b --- /dev/null +++ b/spring-webflow-samples/booking-mvc/src/main/resources/log4j.xml @@ -0,0 +1,44 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/spring-webflow-samples/booking-mvc/src/main/webapp/WEB-INF/config/application-layer-config.xml b/spring-webflow-samples/booking-mvc/src/main/webapp/WEB-INF/config/application-layer-config.xml deleted file mode 100755 index b9666992..00000000 --- a/spring-webflow-samples/booking-mvc/src/main/webapp/WEB-INF/config/application-layer-config.xml +++ /dev/null @@ -1,44 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/spring-webflow-samples/booking-mvc/src/main/webapp/WEB-INF/config/web-application-config.xml b/spring-webflow-samples/booking-mvc/src/main/webapp/WEB-INF/config/web-application-config.xml deleted file mode 100755 index d225026a..00000000 --- a/spring-webflow-samples/booking-mvc/src/main/webapp/WEB-INF/config/web-application-config.xml +++ /dev/null @@ -1,60 +0,0 @@ - - - - - - - - - - /intro=urlFilenameController - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - \ No newline at end of file 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 new file mode 100755 index 00000000..30b41d0a --- /dev/null +++ b/spring-webflow-samples/booking-mvc/src/main/webapp/WEB-INF/intro.jsp @@ -0,0 +1,28 @@ +<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %> +<%@ taglib prefix="tiles" uri="http://tiles.apache.org/tags-tiles" %> + + + + + +
+

Welcome to the Spring Web Flow + Spring MVC Sample Application

+

+ This hotel booking sample application illustrates Spring Web Flow in a Spring MVC environment. + The key features illustrated in this sample include: +

+
    +
  • A unified navigation model
  • +
  • A robust state management model
  • +
  • Modularization of web application functionality by domain responsibility
  • +
  • Flow-managed persistence contexts with the Java Persistence API (JPA)
  • +
  • OGNL Expression Language (EL) integration
  • +
  • Spring IDE integration, with support for graphical flow modeling
  • +
+

+ Start your hotel booking experience +

+
+ +
+
diff --git a/spring-webflow-samples/booking-mvc/src/main/webapp/template.jsp b/spring-webflow-samples/booking-mvc/src/main/webapp/WEB-INF/layouts/standard.jsp similarity index 64% rename from spring-webflow-samples/booking-mvc/src/main/webapp/template.jsp rename to spring-webflow-samples/booking-mvc/src/main/webapp/WEB-INF/layouts/standard.jsp index e454ac44..0dd8307b 100644 --- a/spring-webflow-samples/booking-mvc/src/main/webapp/template.jsp +++ b/spring-webflow-samples/booking-mvc/src/main/webapp/WEB-INF/layouts/standard.jsp @@ -1,17 +1,18 @@ <%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %> <%@ taglib prefix="tiles" uri="http://tiles.apache.org/tags-tiles" %> +<%@ taglib prefix="security" uri="http://www.springframework.org/security/tags" %> Spring Faces: Hotel Booking Sample Application @@ -20,7 +21,15 @@
Spring Web Flow + Spring MVC: Hotel Booking Sample Application
- Welcome, ${user.name} + + + Welcome ${currentUser.name}! + + ">Logout + + + ">Login +
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 new file mode 100755 index 00000000..9f34aa20 --- /dev/null +++ b/spring-webflow-samples/booking-mvc/src/main/webapp/WEB-INF/login.jsp @@ -0,0 +1,62 @@ +<%@ 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" %> + +<%@ page import="org.springframework.security.ui.AbstractProcessingFilter" %> +<%@ page import="org.springframework.security.ui.webapp.AuthenticationProcessingFilter" %> +<%@ page import="org.springframework.security.AuthenticationException" %> + + + + + + +

Login

+ + +
+ Your login attempt was not successful, try again.

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

Valid users:

+
    +
  • rod/koala
  • +
  • dianne/emu
  • +
  • scott/wombat
  • +
+
+ +
+
" method="post"> +
+
+
User:
+
+ value="<%= session.getAttribute(AuthenticationProcessingFilter.SPRING_SECURITY_LAST_USERNAME_KEY) %>"> +
+
+
+
Password:
+
+ +
+
+
+
Don't ask for my password for two weeks:
+
+ +
+
+
+
+ +
+
+
+ + +
+
\ No newline at end of file diff --git a/spring-webflow-samples/booking-mvc/src/main/webapp/WEB-INF/logout-success.jsp b/spring-webflow-samples/booking-mvc/src/main/webapp/WEB-INF/logout-success.jsp new file mode 100755 index 00000000..51b095af --- /dev/null +++ b/spring-webflow-samples/booking-mvc/src/main/webapp/WEB-INF/logout-success.jsp @@ -0,0 +1,16 @@ +<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %> +<%@ taglib prefix="tiles" uri="http://tiles.apache.org/tags-tiles" %> + + + + + + +
+

Logout

+

You have successfully logged out.

+
+ + +
+
\ No newline at end of file diff --git a/spring-webflow-samples/booking-mvc/src/main/webapp/WEB-INF/web-application-config.xml b/spring-webflow-samples/booking-mvc/src/main/webapp/WEB-INF/web-application-config.xml new file mode 100755 index 00000000..bfdbd348 --- /dev/null +++ b/spring-webflow-samples/booking-mvc/src/main/webapp/WEB-INF/web-application-config.xml @@ -0,0 +1,148 @@ + + + + + + + /intro=urlFilenameController + /login=urlFilenameController + /logout-success=urlFilenameController + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ 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 e47e9f50..272b8f47 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,9 +4,52 @@ xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd" version="2.4"> + + + contextConfigLocation + + /WEB-INF/web-application-config.xml + + + + + springSecurityFilterChain + org.springframework.web.filter.DelegatingFilterProxy + + + + springSecurityFilterChain + /* + + + + + org.springframework.web.context.ContextLoaderListener + + org.apache.tiles.web.startup.TilesListener + + + + Resources Servlet + org.springframework.faces.ui.resource.ResourceServlet + 0 + + + + + Resources Servlet + /resources/* + @@ -14,7 +57,7 @@ org.springframework.web.servlet.DispatcherServlet contextConfigLocation - /WEB-INF/config/web-application-config.xml + /WEB-INF/web-application-config.xml 1 diff --git a/spring-webflow-samples/booking-mvc/src/main/webapp/css/booking.css b/spring-webflow-samples/booking-mvc/src/main/webapp/css/booking.css index 7c9359d8..1319ecf6 100644 --- a/spring-webflow-samples/booking-mvc/src/main/webapp/css/booking.css +++ b/spring-webflow-samples/booking-mvc/src/main/webapp/css/booking.css @@ -165,4 +165,9 @@ #footer.spring img { float: right; padding-right: 20px; + } + + div#header a { + color: inherit; + background-color: inherit; } \ No newline at end of file diff --git a/spring-webflow-samples/booking-mvc/src/main/webapp/flow/booking/booking-beans.xml b/spring-webflow-samples/booking-mvc/src/main/webapp/flow/booking/booking-beans.xml deleted file mode 100755 index 141de522..00000000 --- a/spring-webflow-samples/booking-mvc/src/main/webapp/flow/booking/booking-beans.xml +++ /dev/null @@ -1,10 +0,0 @@ - - - - - - \ No newline at end of file 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 deleted file mode 100755 index d33e0d09..00000000 --- a/spring-webflow-samples/booking-mvc/src/main/webapp/flow/booking/booking.xml +++ /dev/null @@ -1,62 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - \ No newline at end of file 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 deleted file mode 100755 index df381eb6..00000000 --- a/spring-webflow-samples/booking-mvc/src/main/webapp/flow/booking/bookingForm.jsp +++ /dev/null @@ -1,135 +0,0 @@ -<%@ 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" %> - - - - -
-

Book Hotel

-
- -
- - -
-
-
Name:
-
${hotel.name}
-
-
-
Address:
-
${hotel.address}
-
-
-
City, State:
-
${hotel.city}, ${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/booking/confirmBooking.jsp b/spring-webflow-samples/booking-mvc/src/main/webapp/flow/booking/confirmBooking.jsp deleted file mode 100755 index f627aa43..00000000 --- a/spring-webflow-samples/booking-mvc/src/main/webapp/flow/booking/confirmBooking.jsp +++ /dev/null @@ -1,64 +0,0 @@ -<%@ 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" %> - - - - -
-

Confirm Hotel Booking

-
- -
- -
-
-
Name:
-
${hotel.name}
-
-
-
Address:
-
${hotel.address}
-
-
-
City, State:
-
${hotel.city}, ${hotel.state}
-
-
-
Zip:
-
${hotel.zip}
-
-
-
Country:
-
${hotel.country}
-
-
-
Total payment:
-
- ${status.value} -
-
-
-
Check In Date:
-
${status.value}
-
-
-
Check Out Date:
-
${status.value}
-
-
-
Credit Card #:
-
${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 deleted file mode 100755 index 0102febe..00000000 --- a/spring-webflow-samples/booking-mvc/src/main/webapp/flow/booking/hotelDetails.jsp +++ /dev/null @@ -1,55 +0,0 @@ -<%@ 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" %> - - - - -
-

View Hotel

-
- -
- -
-
-
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-beans.xml b/spring-webflow-samples/booking-mvc/src/main/webapp/flow/main/main-beans.xml deleted file mode 100755 index c7bcf493..00000000 --- a/spring-webflow-samples/booking-mvc/src/main/webapp/flow/main/main-beans.xml +++ /dev/null @@ -1,12 +0,0 @@ - - - - - - - - \ 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 deleted file mode 100755 index 83e3ebc7..00000000 --- a/spring-webflow-samples/booking-mvc/src/main/webapp/flow/main/main.jsp +++ /dev/null @@ -1,91 +0,0 @@ -<%@ 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" %> - - - - - -
- - - -

Search Hotels

-
- - - - - - - - -
-
- -
- - - - - - - - - - - - - - - - - - - - - -
NameAddressCity, StateZipAction
${hotel.name}${hotel.address}${hotel.city}, ${hotel.state}, ${hotel.country}${hotel.zip} - View Hotel -
-
- -
-

Current Hotel Bookings

-
- -
- - - - - - - - - - - - - - - - - - - - - - - - - -
NameAddressCity, StateCheck in DateCheck out DateConfirmation NumberAction
${booking.hotel.name}${booking.hotel.address}${booking.hotel.city}, ${booking.hotel.state}${booking.checkinDate}${booking.checkoutDate}${booking.id} - Cancel -
-
- -
- -
-
\ No newline at end of file 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 deleted file mode 100755 index f1155008..00000000 --- a/spring-webflow-samples/booking-mvc/src/main/webapp/flow/main/main.xml +++ /dev/null @@ -1,55 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/spring-webflow-samples/booking-mvc/src/main/webapp/intro.jsp b/spring-webflow-samples/booking-mvc/src/main/webapp/intro.jsp deleted file mode 100755 index 06ff6172..00000000 --- a/spring-webflow-samples/booking-mvc/src/main/webapp/intro.jsp +++ /dev/null @@ -1,67 +0,0 @@ -<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %> - - - - - Spring Faces: Hotel Booking Sample Application - - - -
- -
-
- - " alt="The Westin Diplomat in Hollywood, Florida"/> - - - " alt="The Spring Experience"/> - -

- The features illustrated in this sample are just the beginning. - To see what is in store for developing rich web applications with Spring, join us at - The Spring Experience - December 12 - 15, 2007 at the Westin Diplomat in Hollywood, Florida. -

-
-
-
-

Welcome to the Spring Web Flow + Spring MVC Sample Application

-

- This hotel booking sample application illustrates Spring Web Flow in a Spring MVC environment. - The key features illustrated in this sample include: -

-
    -
  • A unified navigation model
  • -
  • A robust state management model
  • -
  • Modularization of web application functionality by domain responsibility
  • -
  • Flow-managed persistence contexts with the Java Persistence API (JPA)
  • -
  • OGNL Expression Language (EL) integration
  • -
  • Spring IDE integration, with support for graphical flow modeling
  • -
-

- Start your hotel booking experience -

-
-
-
- -
- - \ No newline at end of file