This commit is contained in:
Keith Donald
2008-03-27 12:19:39 +00:00
parent b5d11bffc0
commit 62ddcb31fa
3 changed files with 27 additions and 10 deletions

View File

@@ -1,5 +1,6 @@
package org.springframework.webflow.samples.booking;
import java.security.Principal;
import java.util.List;
import org.springframework.web.bind.annotation.ModelAttribute;
@@ -15,7 +16,13 @@ public class HotelsController {
}
@RequestMapping(method = RequestMethod.GET)
public void index(SearchCriteria searchCriteria) {
@ModelAttribute("bookings")
public List<Booking> index(SearchCriteria searchCriteria, Principal currentUser) {
if (currentUser != null) {
return bookingService.findBookings(currentUser.getName());
} else {
return null;
}
}
@RequestMapping
@@ -29,4 +36,10 @@ public class HotelsController {
return bookingService.findHotelById(id);
}
@RequestMapping(method = RequestMethod.GET)
public String deleteBooking(@RequestParam("id") Long id) {
bookingService.cancelBooking(id);
return "redirect:index";
}
}

View File

@@ -23,8 +23,8 @@
<div class="left">Spring Travel: Spring MVC and Web Flow Reference Application</div>
<div class="right">
<security:authorize ifAllGranted="ROLE_USER">
<c:if test="${not empty currentUser}">
Welcome, ${currentUser.name} |
<c:if test="${pageContext.request.userPrincipal != null}">
Welcome, ${pageContext.request.userPrincipal.name} |
</c:if>
<a href="<c:url value="/spring/logout" />">Logout</a>
</security:authorize>

View File

@@ -23,25 +23,29 @@
</value>
</property>
<property name="defaultHandler">
<!-- Handles requests mapped directly to facelet .xhtml view templates -->
<!-- Handles requests mapped directly to view templates -->
<bean class="org.springframework.web.servlet.mvc.UrlFilenameViewController" />
</property>
</bean>
<!-- Handles requests to search hotels and display hotel details -->
<!-- Handles requests to search hotels, display hotel details, and cancel hotel bookings -->
<bean id="hotelsController" class="org.springframework.webflow.samples.booking.HotelsController">
<constructor-arg ref="bookingService"/>
<constructor-arg ref="bookingService" />
</bean>
<!-- Controls access to the booking flow -->
<!-- Controls access to the hotel booking flow -->
<bean id="bookingFlowHandler" class="org.springframework.webflow.samples.booking.BookingFlowHandler" />
<!-- Handles requests mapped to the Web Flow handlers -->
<!-- Enables annotated POJO @Controllers -->
<bean class="org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter" />
<!-- Enables plain Controllers -->
<bean class="org.springframework.web.servlet.mvc.SimpleControllerHandlerAdapter" />
<!-- Enables FlowHandlers -->
<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">