Adding ability to resolve flow-local Spring Beans from EL expressions.

This commit is contained in:
Jeremy Grelle
2008-02-26 23:03:54 +00:00
parent fca5617750
commit a98eb431b0
10 changed files with 577 additions and 24 deletions

View File

@@ -2,11 +2,14 @@
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:web="http://www.springframework.org/schema/webflow-config"
xmlns:faces="http://www.springframework.org/schema/faces-config"
xsi:schemaLocation="
http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
http://www.springframework.org/schema/webflow-config
http://www.springframework.org/schema/webflow-config/spring-webflow-config-2.0.xsd">
http://www.springframework.org/schema/webflow-config/spring-webflow-config-2.0.xsd
http://www.springframework.org/schema/faces-config
http://www.springframework.org/schema/faces-config/spring-faces-config-2.0.xsd">
<!-- Imports the "application-layer" definining business logic and data access services -->
<import resource="application-layer-config.xml"/>
@@ -16,34 +19,17 @@
</bean>
<web:flow-executor id="flowExecutor" flow-registry="flowRegistry">
<web:flow-execution-attributes>
<web:alwaysRedirectOnPause value="true" />
</web:flow-execution-attributes>
<web:flow-execution-listeners>
<web:listener ref="jpaFlowExecutionListener" criteria="*" />
<web:listener ref="jpaFlowExecutionListener" criteria="*"/>
</web:flow-execution-listeners>
</web:flow-executor>
<web:flow-registry id="flowRegistry" flow-builder-services="flowBuilderServices">
<web:flow-location path="flow/main/main.xml" />
<web:flow-location path="flow/booking/booking.xml" />
<web:flow-registry id="flowRegistry" flow-builder-services="facesServices">
<web:flow-location path="/WEB-INF/flow/main/main.xml" />
<web:flow-location path="/WEB-INF/flow/booking/booking.xml" />
</web:flow-registry>
<bean id="flowBuilderServices" class="org.springframework.webflow.engine.builder.support.FlowBuilderServices">
<property name="expressionParser">
<bean class="org.springframework.webflow.core.expression.el.WebFlowELExpressionParser">
<constructor-arg >
<bean class="org.jboss.el.ExpressionFactoryImpl" />
</constructor-arg>
</bean>
</property>
<property name="viewFactoryCreator">
<bean class="org.springframework.faces.webflow.JsfViewFactoryCreator"/>
</property>
<property name="conversionService">
<bean class="org.springframework.faces.model.converter.FacesConversionService"/>
</property>
</bean>
<faces:flow-builder-services id="facesServices"/>
<!-- Installs a listener that manages JPA persistence contexts for flows that require them -->
<bean id="jpaFlowExecutionListener" class="org.springframework.webflow.persistence.JpaFlowExecutionListener">

View File

@@ -0,0 +1,10 @@
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="
http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-2.0.xsd">
<bean id="bookingActions" class="org.springframework.webflow.samples.booking.flow.booking.BookingActions"/>
</beans>

View File

@@ -0,0 +1,58 @@
<?xml version="1.0" encoding="UTF-8"?>
<flow xmlns="http://www.springframework.org/schema/webflow"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/webflow
http://www.springframework.org/schema/webflow/spring-webflow-2.0.xsd">
<attribute name="description" value="The flow that handles the process of booking a hotel for a user"/>
<!--
Indicates this flow requires a persistence context
One will be created automatically when this flow starts; all data access will use it automatically
-->
<attribute name="persistenceContext" value="true" />
<var name="bookingOptions" class="org.springframework.webflow.samples.booking.flow.booking.BookingOptions"/>
<input-mapper>
<input-attribute name="#{id}" scope="flow" />
</input-mapper>
<start-state idref="loadHotel"/>
<action-state id="loadHotel">
<evaluate-action expression="#{bookingService.findHotelById(id)}" result="#{flowScope.hotel}"/>
<transition on="success" to="createBooking"/>
</action-state>
<action-state id="createBooking">
<action method="createBooking" bean="bookingActions"/>
<transition on="success" to="enterBookingDetails" />
</action-state>
<view-state id="enterBookingDetails" view="bookingForm.xhtml">
<transition on="proceed" to="confirmBooking">
<action method="validateBooking" bean="bookingActions" />
</transition>
<transition on="cancel" to="cancel" />
</view-state>
<view-state id="confirmBooking" view="confirmBooking.xhtml">
<transition on="confirm" to="bookingAuthorized" />
<transition on="revise" to="enterBookingDetails" />
<transition on="cancel" to="cancel" />
</view-state>
<end-state id="cancel">
<!-- Indicates any changes to managed persistent entities should NOT be committed to the database -->
<attribute name="commit" value="false" type="boolean" />
</end-state>
<end-state id="bookingAuthorized">
<!-- Indicates changes to managed persistent entities should be committed to the database at this point -->
<attribute name="commit" value="true" type="boolean" />
</end-state>
<import resource="booking-beans.xml"/>
</flow>

View File

@@ -0,0 +1,134 @@
<!DOCTYPE composition PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<ui:composition xmlns="http://www.w3.org/1999/xhtml"
xmlns:ui="http://java.sun.com/jsf/facelets"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:f="http://java.sun.com/jsf/core"
xmlns:sf="http://www.springframework.org/tags/faces"
xmlns:sfe="http://www.springframework.org/tags/faces-ext"
template="/template.xhtml">
<ui:define name="content">
<div class="section">
<h2>Book Hotel</h2>
<h:form id="booking">
<h:messages errorClass="errors" />
<fieldset>
<div class="field">
<div class="label">Name:</div>
<div class="output">#{hotel.name}</div>
</div>
<div class="field">
<div class="label">Address:</div>
<div class="output">#{hotel.address}</div>
</div>
<div class="field">
<div class="label">City, State:</div>
<div class="output">#{hotel.city}, #{hotel.state}</div>
</div>
<div class="field">
<div class="label">Zip:</div>
<div class="output">#{hotel.zip}</div>
</div>
<div class="field">
<div class="label">Country:</div>
<div class="output">#{hotel.country}</div>
</div>
<div class="field">
<div class="label">Nightly rate:</div>
<div class="output">
<h:outputText value="#{hotel.price}">
<f:convertNumber type="currency" currencySymbol="$"/>
</h:outputText>
</div>
</div>
<div class="field">
<div class="label">
<h:outputLabel for="checkinDate">Check In Date:</h:outputLabel>
</div>
<div class="input">
<sf:clientDateValidator required="true" >
<h:inputText id="checkinDate" value="#{booking.checkinDate}" required="true">
<f:convertDateTime pattern="yyyy-MM-dd" timeZone="EST"/>
</h:inputText>
</sf:clientDateValidator>
</div>
</div>
<div class="field">
<div class="label">
<h:outputLabel for="checkoutDate">Check Out Date:</h:outputLabel>
</div>
<div class="input">
<sf:clientDateValidator required="true">
<h:inputText id="checkoutDate" value="#{booking.checkoutDate}" required="true">
<f:convertDateTime pattern="yyyy-MM-dd" timeZone="EST"/>
</h:inputText>
</sf:clientDateValidator>
</div>
</div>
<div class="field">
<div class="label">
<h:outputLabel for="beds">Room Preference:</h:outputLabel>
</div>
<div class="input">
<h:selectOneMenu id="beds" value="#{booking.beds}">
<f:selectItems value="#{bookingOptions.bedOptions}"/>
</h:selectOneMenu>
</div>
</div>
<div class="field">
<div class="label">
<h:outputLabel for="smoking">Smoking Preference:</h:outputLabel>
</div>
<div id="radio" class="input">
<h:selectOneRadio id="smoking" value="#{booking.smoking}" layout="pageDirection">
<f:selectItems value="#{bookingOptions.smokingOptions}"/>
</h:selectOneRadio>
</div>
</div>
<div class="field">
<div class="label">
<h:outputLabel for="creditCard">Credit Card #:</h:outputLabel>
</div>
<div class="input">
<sf:clientTextValidator required="true" regExp="[0-9]{16}" invalidMessage="A 16-digit credit card number is required.">
<h:inputText id="creditCard" value="#{booking.creditCard}" required="true"/>
</sf:clientTextValidator>
</div>
</div>
<div class="field">
<div class="label">
<h:outputLabel for="creditCardName">Credit Card Name:</h:outputLabel>
</div>
<div class="input">
<sf:clientTextValidator required="true">
<h:inputText id="creditCardName" value="#{booking.creditCardName}" required="true"/>
</sf:clientTextValidator>
</div>
</div>
<div class="field">
<div class="label">
<h:outputLabel for="creditCardExpiryMonth">Credit Card Expiry:</h:outputLabel>
</div>
<div class="input">
<h:selectOneMenu id="creditCardExpiryMonth" value="#{booking.creditCardExpiryMonth}">
<f:selectItems value="#{bookingOptions.creditCardExpMonths}" />
</h:selectOneMenu>
<h:selectOneMenu id="creditCardExpiryYear" value="#{booking.creditCardExpiryYear}">
<f:selectItems value="#{bookingOptions.creditCardExpYears}"/>
</h:selectOneMenu>
</div>
</div>
<div class="buttonGroup">
<sf:validateAllOnClick>
<h:commandButton id="proceed" action="proceed" value="Proceed"/>
</sf:validateAllOnClick>
<h:commandButton id="cancel" immediate="true" value="Cancel" action="cancel"/>
</div>
</fieldset>
</h:form>
</div>
</ui:define>
</ui:composition>

View File

@@ -0,0 +1,69 @@
<!DOCTYPE composition PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<ui:composition xmlns="http://www.w3.org/1999/xhtml"
xmlns:ui="http://java.sun.com/jsf/facelets"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:f="http://java.sun.com/jsf/core"
template="/template.xhtml">
<ui:define name="content">
<div class="section">
<h1>Confirm Hotel Booking</h1>
</div>
<div class="section">
<h:form id="confirm">
<fieldset>
<div class="field">
<div class="label">Name:</div>
<div class="output">#{hotel.name}</div>
</div>
<div class="field">
<div class="label">Address:</div>
<div class="output">#{hotel.address}</div>
</div>
<div class="field">
<div class="label">City, State:</div>
<div class="output">#{hotel.city}, #{hotel.state}</div>
</div>
<div class="field">
<div class="label">Zip:</div>
<div class="output">#{hotel.zip}</div>
</div>
<div class="field">
<div class="label">Country:</div>
<div class="output">#{hotel.country}</div>
</div>
<div class="field">
<div class="label">Total payment:</div>
<div class="output">
<h:outputText value="#{booking.total}">
<f:convertNumber type="currency"
currencySymbol="$"/>
</h:outputText>
</div>
</div>
<div class="field">
<div class="label">Check In Date:</div>
<div class="output"><h:outputText value="#{booking.checkinDate}"/></div>
</div>
<div class="field">
<div class="label">Check Out Date:</div>
<div class="output"><h:outputText value="#{booking.checkoutDate}"/></div>
</div>
<div class="field">
<div class="label">Credit Card #:</div>
<div class="output">#{booking.creditCard}</div>
</div>
<div class="buttonGroup">
<h:commandButton id="confirm" value="Confirm" action="confirm"/>&#160;
<h:commandButton id="revise" value="Revise" action="revise"/>&#160;
<h:commandButton id="cancel" value="Cancel" action="cancel"/>
</div>
</fieldset>
</h:form>
</div>
</ui:define>
</ui:composition>

View File

@@ -0,0 +1,57 @@
<!DOCTYPE composition PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<ui:composition xmlns="http://www.w3.org/1999/xhtml"
xmlns:ui="http://java.sun.com/jsf/facelets"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:f="http://java.sun.com/jsf/core"
xmlns:sf="http://www.springframework.org/tags/faces"
template="/template.xhtml">
<ui:define name="content">
<h:form id="displayHotelsForm">
<div class="section">
<sf:commandLink ajaxEnabled="false" value="Return to Main" action="changeSearch"/>
<h2>Hotel Results</h2>
<p>
<b>Search Criteria:</b> #{searchCriteria}<br/>
<sf:commandLink value="Edit Criteria" action="changeSearch"/>
</p>
<ui:fragment id="searchResultsFragment">
<div id="searchResults">
<h:outputText id="noHotelsTxt" value="No Hotels Found" rendered="#{hotels.rowCount==0}"/>
<h:dataTable id="hotels" styleClass="summary" value="#{hotels}" var="hotel" rendered="#{hotels.rowCount > 0}">
<h:column>
<f:facet name="header">Name</f:facet>
#{hotel.name}
</h:column>
<h:column>
<f:facet name="header">Address</f:facet>
#{hotel.address}
</h:column>
<h:column>
<f:facet name="header">City, State</f:facet>
#{hotel.city}, #{hotel.state}, #{hotel.country}
</h:column>
<h:column>
<f:facet name="header">Zip</f:facet>
#{hotel.zip}
</h:column>
<h:column>
<f:facet name="header">Action</f:facet>
<!-- @TODO - THIS LINK DOES NOT WORK ON MYFACES 1.2.0 WHEN AJAX IS ENABLED BECAUSE THEY HAVE NOT IMPLEMENTED UIData.invokeOnComponent -->
<sf:commandLink id="viewHotelLink" value="View Hotel" action="selectHotel"/>
</h:column>
</h:dataTable>
<div class="next">
<sf:commandLink id="nextPageLink" value="More Results" action="next"
rendered="#{not empty hotels and hotels.rowCount == searchCriteria.pageSize}"/>
</div>
<div class="prev">
<sf:commandLink id="prevPageLink" value="Previous results" action="previous"
rendered="#{searchCriteria.page > 0}"/>
</div>
</div>
</ui:fragment>
</div>
</h:form>
</ui:define>
</ui:composition>

View File

@@ -0,0 +1,56 @@
<!DOCTYPE composition PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<ui:composition xmlns="http://www.w3.org/1999/xhtml"
xmlns:ui="http://java.sun.com/jsf/facelets"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:f="http://java.sun.com/jsf/core"
template="/template.xhtml">
<ui:define name="content">
<div class="section">
<h2>View Hotel</h2>
<div class="field">
<div class="label">Name:</div>
<div class="output">#{hotel.name}</div>
</div>
<div class="field">
<div class="label">Address:</div>
<div class="output">#{hotel.address}</div>
</div>
<div class="field">
<div class="label">City:</div>
<div class="output">#{hotel.city}</div>
</div>
<div class="field">
<div class="label">State:</div>
<div class="output">#{hotel.state}</div>
</div>
<div class="field">
<div class="label">Zip:</div>
<div class="output">#{hotel.zip}</div>
</div>
<div class="field">
<div class="label">Country:</div>
<div class="output">#{hotel.country}</div>
</div>
<div class="field">
<div class="label">Nightly rate:</div>
<div class="output">
<h:outputText value="#{hotel.price}">
<f:convertNumber type="currency" currencySymbol="$"/>
</h:outputText>
</div>
</div>
</div>
<div class="section">
<h:form id="hotel">
<fieldset class="buttonGroup">
<h:commandButton id="book" action="book" value="Book Hotel"/>
<h:commandButton id="cancel" action="cancel" value="Back to Search"/>
</fieldset>
</h:form>
</div>
</ui:define>
</ui:composition>

View File

@@ -0,0 +1,12 @@
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="
http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-2.0.xsd">
<bean id="mainActions" class="org.springframework.webflow.samples.booking.flow.main.MainActions">
<constructor-arg ref="bookingService" />
</bean>
</beans>

View File

@@ -0,0 +1,87 @@
<!DOCTYPE composition PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<ui:composition xmlns="http://www.w3.org/1999/xhtml"
xmlns:ui="http://java.sun.com/jsf/facelets"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:f="http://java.sun.com/jsf/core"
xmlns:sf="http://www.springframework.org/tags/faces"
template="/template.xhtml">
<ui:define name="content">
<ui:fragment id="hotelSearchFragment">
<div id="hotelSearch" class="section">
<span class="errors">
<h:messages globalOnly="true"/>
</span>
<h2>Search Hotels</h2>
<h:form id="mainForm">
<br/>
<br/>
<fieldset>
<div class="searchGroup">
<div class="searchField">
<sf:clientTextValidator promptMessage="Search hotels by name, address, city or zip.">
<h:inputText id="searchString" value="#{flowScope.searchCriteria.searchString}" style="width: 165px; height: 15px;"/>
</sf:clientTextValidator>
</div>
<div class="searchSize">
<h:outputLabel for="pageSize">Maximum results:</h:outputLabel>
<h:selectOneMenu value="#{flowScope.searchCriteria.pageSize}" id="pageSize">
<f:selectItem itemLabel="5" itemValue="5"/>
<f:selectItem itemLabel="10" itemValue="10"/>
<f:selectItem itemLabel="20" itemValue="20"/>
</h:selectOneMenu>
</div>
<div class="searchButton">
<sf:commandButton id="findHotels" value="Find Hotels" processIds="*" actionListener="#{searchCriteria.findHotelsListener}" action="findHotels"/>
</div>
</div>
</fieldset>
</h:form>
</div>
</ui:fragment>
<ui:fragment id="bookingsSection">
<div class="section">
<h:form id="bookingsForm">
<h2>Current Hotel Bookings</h2>
<h:outputText value="No Bookings Found" rendered="#{bookings.rowCount == 0}"/>
<h:dataTable id="bookings" styleClass="summary" value="#{bookings}" var="booking" rendered="#{bookings.rowCount > 0}">
<h:column>
<f:facet name="header">Name</f:facet>
#{booking.hotel.name}
</h:column>
<h:column>
<f:facet name="header">Address</f:facet>
#{booking.hotel.address}
</h:column>
<h:column>
<f:facet name="header">City, State</f:facet>
#{booking.hotel.city}, #{booking.hotel.state}
</h:column>
<h:column>
<f:facet name="header">Check in date</f:facet>
<h:outputText value="#{booking.checkinDate}"/>
</h:column>
<h:column>
<f:facet name="header">Check out date</f:facet>
<h:outputText value="#{booking.checkoutDate}"/>
</h:column>
<h:column>
<f:facet name="header">Confirmation number</f:facet>
#{booking.id}
</h:column>
<h:column>
<f:facet name="header">Action</f:facet>
<!-- @TODO - THIS LINK DOES NOT WORK ON MYFACES 1.2.0 WHEN AJAX IS ENABLED BECAUSE THEY HAVE NOT IMPLEMENTED UIData.invokeOnComponent -->
<sf:commandLink id="cancel" value="Cancel" ajaxEnabled="false" processIds="bookingsSection" action="cancelBooking"/>
</h:column>
</h:dataTable>
</h:form>
</div>
</ui:fragment>
</ui:define>
</ui:composition>

View File

@@ -0,0 +1,84 @@
<?xml version="1.0" encoding="UTF-8"?>
<flow xmlns="http://www.springframework.org/schema/webflow"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/webflow
http://www.springframework.org/schema/webflow/spring-webflow-2.0.xsd">
<attribute name="description" value="The main flow of the application that handles searching for hotels to book"/>
<var name="searchCriteria" class="org.springframework.webflow.samples.booking.flow.main.SearchCriteria" scope="flow" />
<start-actions>
<action method="initCurrentUser" bean="mainActions" />
<evaluate-action expression="#{bookingService.findBookings(user.username)}" result="#{flowScope.bookings}"
type="selectOneDataModel"/>
</start-actions>
<start-state idref="displayMain"/>
<view-state id="displayMain" view="/WEB-INF/flow/main/main.xhtml">
<transition on="findHotels" to="findHotels" />
<transition on="cancelBooking" to="cancelBooking" />
</view-state>
<view-state id="findHotels" view="displayHotels.xhtml">
<render-actions>
<evaluate-action expression="#{bookingService.findHotels(searchCriteria.searchString, searchCriteria.pageSize, searchCriteria.page)}"
result="#{flowScope.hotels}" type="selectOneDataModel"/>
</render-actions>
<transition on="previous" to="findHotels">
<evaluate-action expression="#{searchCriteria.prevPage()}"/>
<set attribute="#{flashScope.renderIds}" value="searchResultsFragment"/>
</transition>
<transition on="next" to="findHotels">
<evaluate-action expression="#{searchCriteria.nextPage()}"/>
<set attribute="#{flashScope.renderIds}" value="searchResultsFragment"/>
</transition>
<transition on="selectHotel" to="displayHotel"/>
<transition on="changeSearch" to="editSearchPopup"/>
</view-state>
<view-state id="editSearchPopup" view="main.xhtml">
<attribute name="modal" value="true" type="java.lang.Boolean"/>
<entry-actions>
<set attribute="#{flashScope.renderIds}" value="hotelSearchFragment"/>
</entry-actions>
<transition on="findHotels" to="findHotels" />
</view-state>
<view-state id="displayHotel" view="hotelDetails.xhtml">
<render-actions>
<set attribute="#{hotel}" value="#{hotels.selectedRow}" scope="request"/>
</render-actions>
<transition on="book" to="bookHotel" />
<transition on="cancel" to="displayMain" />
</view-state>
<subflow-state id="bookHotel" flow="booking">
<attribute-mapper>
<input-mapper>
<mapping source="#{hotels.selectedRow.id}" target="#{id}"/>
</input-mapper>
</attribute-mapper>
<transition on="bookingAuthorized" to="reloadCurrentUserBookings" />
<transition on="cancel" to="displayMain" />
</subflow-state>
<action-state id="cancelBooking">
<bean-action method="cancelBooking" bean="bookingService">
<method-arguments>
<argument expression="#{bookings.selectedRow.id}" parameter-type="long"/>
</method-arguments>
</bean-action>
<transition on="success" to="reloadCurrentUserBookings" />
</action-state>
<action-state id="reloadCurrentUserBookings">
<evaluate-action expression="#{bookingService.findBookings(user.username)}" result="#{flowScope.bookings}"
type="selectOneDataModel"/>
<transition on="success" to="displayMain" />
</action-state>
<import resource="main-beans.xml"/>
</flow>