This commit is contained in:
Keith Donald
2008-09-18 15:31:55 +00:00
parent 6ed4d0a0c2
commit 075e524bc6
7 changed files with 89 additions and 73 deletions

View File

@@ -16,7 +16,7 @@
</para>
<programlisting language="xml"><![CDATA[
<action-state id="moreAnswersNeeded">
<evaluate expression="interview.moreAnswersNeeded()"/>
<evaluate expression="interview.moreAnswersNeeded()" />
<transition on="yes" to="answerQuestions" />
<transition on="no" to="finish" />
</action-state>
@@ -36,16 +36,16 @@
</on-start>
<view-state id="answerQuestions" model="questionSet">
<on-entry>
<on-entry>
<evaluate expression="interview.getNextQuestionSet()" result="viewScope.questionSet" />
</on-entry>
</on-entry>
<transition on="submitAnswers" to="moreAnswersNeeded">
<evaluate expression="interview.recordAnswers(questionSet)" />
</transition>
</view-state>
<action-state id="moreAnswersNeeded">
<evaluate expression="interview.moreAnswersNeeded()"/>
<evaluate expression="interview.moreAnswersNeeded()" />
<transition on="yes" to="answerQuestions" />
<transition on="no" to="finish" />
</action-state>
@@ -63,7 +63,7 @@
</para>
<programlisting language="xml"><![CDATA[
<decision-state id="moreAnswersNeeded">
<if test="interview.moreAnswersNeeded" then="answerQuestions" else="finish"/>
<if test="interview.moreAnswersNeeded" then="answerQuestions" else="finish" />
</decision-state>
]]>
</programlisting>
@@ -163,7 +163,8 @@
<programlisting language="xml"><![CDATA[
<view-state id="editOrder">
<on-entry>
<evaluate expression="orderService.selectForUpdate(orderId, currentUser)" result="viewScope.order" />
<evaluate expression="orderService.selectForUpdate(orderId, currentUser)"
result="viewScope.order" />
</on-entry>
<transition on="save" to="finish">
<evaluate expression="orderService.update(order, currentUser)" />
@@ -188,7 +189,8 @@
<input name="orderId" />
<on-start>
<evaluate expression="orderService.selectForUpdate(orderId, currentUser)" result="flowScope.order" />
<evaluate expression="orderService.selectForUpdate(orderId, currentUser)"
result="flowScope.order" />
</on-start>
<view-state id="editOrder">
@@ -212,7 +214,8 @@
<programlisting language="xml"><![CDATA[
<view-state id="reviewHotels">
<on-render>
<evaluate expression="bookingService.findHotels(searchCriteria)" result="viewScope.hotels" result-type="dataModel" />
<evaluate expression="bookingService.findHotels(searchCriteria)"
result="viewScope.hotels" result-type="dataModel" />
</on-render>
<transition on="select" to="reviewHotel">
<set name="flowScope.hotel" value="hotels.selectedRow" />

View File

@@ -340,7 +340,7 @@ public interface FlowOutcome {
<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">;
http://www.springframework.org/schema/webflow/spring-webflow-2.0.xsd">
<input name="hotelId" />

View File

@@ -99,10 +99,10 @@
An <code>AjaxEventDecoration</code> applies a client-side event listener that fires a remote Ajax request to the server. It also auto-registers a callback function to link in the response:
</para>
<programlisting language="xml"><![CDATA[
<a id="prevResultsLink" href="search?searchString=${searchCriteria.searchString}&page=${searchCriteria.page - 1}">Previous Results</a>
<a id="prevLink" href="search?searchString=${criteria.searchString}&page=${criteria.page - 1}">Previous</a>
<script type="text/javascript">
Spring.addDecoration(new Spring.AjaxEventDecoration({
elementId: "prevResultsLink",
elementId: "prevLink",
event: "onclick",
params: { fragments: "body" }
}));
@@ -119,7 +119,7 @@
</para>
<programlisting language="xml"><![CDATA[
<input type="submit" id="proceed" name="_eventId_proceed" value="Proceed"
onclick="Spring.remoting.submitForm('proceed', 'booking', { fragments:'messages,bookingForm' }); return false;" />
onclick="Spring.remoting.submitForm('proceed', 'booking', { fragments:'messages' }); return false;" />
<script type="text/javascript">
Spring.addDecoration(new Spring.ValidateAllDecoration({ elementId:'proceed', event:'onclick'} ));
</script>]]>

View File

@@ -22,10 +22,10 @@
<book>
<bookinfo>
<title>Spring Web Flow 2 Reference Guide</title>
<subtitle>Reference Documentation</subtitle>
<title>Spring Web Flow Reference Guide</title>
<productname>Spring Web Flow</productname>
<releaseinfo>Version 2.0.4</releaseinfo>
<pubdate>August 2008</pubdate>
<pubdate>September 2008</pubdate>
<authorgroup>
<author>
<firstname>Keith</firstname>

View File

@@ -26,7 +26,7 @@ public class BookingFlowExecutionTests extends AbstractXmlFlowExecutionTests {
<programlisting language="java"><![CDATA[
@Override
protected FlowDefinitionResource getResource(FlowDefinitionResourceFactory resourceFactory) {
return resourceFactory.createFileResource("src/main/webapp/WEB-INF/flows/booking/booking.xml");
return resourceFactory.createFileResource("src/main/webapp/WEB-INF/hotels/booking/booking.xml");
}]]>
</programlisting>
</sect1>
@@ -50,7 +50,7 @@ protected void configureFlowBuilderContext(MockFlowBuilderContext builderContext
@Override
protected FlowDefinitionResource[] getModelResources(FlowDefinitionResourceFactory resourceFactory) {
return new FlowDefinitionResource[] {
resourceFactory.createFileResource("src/main/webapp/WEB-INF/flows/common/common.xml")
resourceFactory.createFileResource("src/main/webapp/WEB-INF/common/common.xml")
};
}]]>
</programlisting>

View File

@@ -180,9 +180,9 @@ java org.springframework.webflow.upgrade.WebFlowUpgrader flow-to-upgrade.xml
</para>
<programlisting language="xml"><![CDATA[
<bean name="/pos.htm" class="org.springframework.webflow.mvc.servlet.FlowController">
<property name="flowExecutor" ref="flowExecutor"/>
<property name="flowExecutor" ref="flowExecutor" />
<property name="flowUrlHandler">
<bean class="org.springframework.webflow.context.servlet.WebFlow1FlowUrlHandler"/>
<bean class="org.springframework.webflow.context.servlet.WebFlow1FlowUrlHandler" />
</property>
</bean>
]]></programlisting>
@@ -206,14 +206,14 @@ java org.springframework.webflow.upgrade.WebFlowUpgrader flow-to-upgrade.xml
</webflow:flow-registry>
<webflow:flow-builder-services id="flowBuilderServices"
view-factory-creator="mvcViewFactoryCreator"/>
view-factory-creator="viewFactoryCreator"/>
<bean id="mvcViewFactoryCreator" class="org.springframework.webflow.mvc.builder.MvcViewFactoryCreator">
<property name="viewResolvers" ref="tilesViewResolver"/>
<bean id="viewFactoryCreator" class="org.springframework.webflow.mvc.builder.MvcViewFactoryCreator">
<property name="viewResolvers" ref="tilesViewResolver" />
</bean>
<bean id="tilesViewResolver" class="org.springframework.web.servlet.view.UrlBasedViewResolver">
<property name="viewClass" value="org.springframework.web.servlet.view.tiles.TilesJstlView"/>
<property name="viewClass" value="org.springframework.web.servlet.view.tiles.TilesJstlView" />
</bean>
<bean class="org.springframework.web.servlet.view.tiles.TilesConfigurer">

View File

@@ -40,7 +40,7 @@
<sect1 id="view-explicit">
<title>Specifying view identifiers</title>
<para>
Use the <code>view</code> attribute to explictly specify the id of the view to render.
Use the <code>view</code> attribute to specify the id of the view to render explicitly.
</para>
<sect2 id="view-explicit-flowrelative">
<title>Flow relative view ids</title>
@@ -113,7 +113,8 @@
<programlisting language="xml"><![CDATA[
<view-state id="searchResults">
<on-render>
<evaluate expression="bookingService.findHotels(searchCriteria)" result="viewScope.hotels" />
<evaluate expression="bookingService.findHotels(searchCriteria)"
result="viewScope.hotels" />
</on-render>
<transition on="next">
<evaluate expression="searchCriteria.nextPage()" />
@@ -335,25 +336,36 @@ public class BookingValidator {
<para>
In this example, data binding will still occur on <code>back</code> but validation will be suppressed.
</para>
</sect1>
<sect1 id="transition-actions">
<title>Transition actions</title>
</sect1>
<sect1 id="view-transitions">
<title>Executing view transitions</title>
<para>
A view-state transition can execute one or more actions before executing.
These actions may return an error result to prevent the transition itself from executing.
If an error result occurs, the view will re-render and should typically display an appropriate error message to the user.
Define one or more <code>transition</code> elements to handle user events that may occur on the view.
A transition may take the user to another view, or it may simply execute an action and re-render the current view.
A transition may also request the rendering of parts of a view called "fragments" when handling an Ajax event.
Finally, "global" transitions that are shared across all views may also be defined.
</para>
<para>
If the transition action invokes a plain Java method, the invoked method may return false to prevent the transition from executing.
This technique can be used to handle exceptions thrown by service-layer methods.
The example below invokes an action that calls a service and handles an exceptional situation:
Implementing view transitions is illustrated in the following sections.
</para>
<programlisting language="xml"><![CDATA[
<sect2 id="transition-actions">
<title>Transition actions</title>
<para>
A view-state transition can execute one or more actions before executing.
These actions may return an error result to prevent the transition from exiting the current view-state.
If an error result occurs, the view will re-render and should display an appropriate message to the user.
</para>
<para>
If the transition action invokes a plain Java method, the invoked method may return false to prevent the transition from executing.
This technique can be used to handle exceptions thrown by service-layer methods.
The example below invokes an action that calls a service and handles an exceptional situation:
</para>
<programlisting language="xml"><![CDATA[
<transition on="submit" to="bookingConfirmed">
<evaluate expression="bookingAction.makeBooking(booking, messageContext)" />
</transition>]]>
</programlisting>
<programlisting language="java"><![CDATA[
</programlisting>
<programlisting language="java"><![CDATA[
public class BookingAction {
public boolean makeBooking(Booking booking, MessageContext context) {
try {
@@ -366,45 +378,12 @@ public class BookingAction {
}
}
}]]>
</programlisting>
</sect1>
<sect1 id="simple-event-handlers">
<title>Handling events</title>
<para>
From a view-state, transitions without targets can also be defined. Such transitions are called "event handlers":
</para>
<programlisting language="xml"><![CDATA[
<transition on="event">
<!-- Handle event -->
</transition>]]>
</programlisting>
<para>
These event handlers do not change the state of the flow.
They simply execute their actions and re-render the current view or one or more fragments of the current view.
</para>
<sect2 id="event-handlers-render">
<title>Rendering partials</title>
<para>
Use the <code>render</code> element to request partial re-rendering of a view after handling an event:
</para>
<programlisting language="xml"><![CDATA[
<transition on="next">
<evaluate expression="searchCriteria.nextPage()" />
<render fragments="searchResultsFragment" />
</transition>]]>
</programlisting>
<para>
The fragments attribute should reference the ID(s) of the view element(s) you wish to re-render.
Specify multiple elements to re-render by separating them with a comma delimiter.
</para>
<para>
Such partial rendering is often used with events signaled by Ajax to update a specific zone of the view.
</para>
</sect2>
<sect2 id="event-handlers-global">
<title>Handling global events</title>
<title>Global transitions</title>
<para>
Use the flow's <code>global-transitions</code> element to create event handlers that apply across all views.
Use the flow's <code>global-transitions</code> element to create transitions that apply across all views.
Global-transitions are often used to handle global menu links that are part of the layout.
</para>
<programlisting language="xml"><![CDATA[
@@ -413,7 +392,41 @@ public class BookingAction {
<transition on="logout" to="logout">
</global-transitions>]]>
</programlisting>
</sect2>
</sect2>
<sect2 id="simple-event-handlers">
<title>Event handlers</title>
<para>
From a view-state, transitions without targets can also be defined. Such transitions are called "event handlers":
</para>
<programlisting language="xml"><![CDATA[
<transition on="event">
<!-- Handle event -->
</transition>]]>
</programlisting>
<para>
These event handlers do not change the state of the flow.
They simply execute their actions and re-render the current view or one or more fragments of the current view.
</para>
</sect2>
<sect2 id="event-handlers-render">
<title>Rendering fragments</title>
<para>
Use the <code>render</code> element within a transition to request partial re-rendering of the current view after handling the event:
</para>
<programlisting language="xml"><![CDATA[
<transition on="next">
<evaluate expression="searchCriteria.nextPage()" />
<render fragments="searchResultsFragment" />
</transition>]]>
</programlisting>
<para>
The fragments attribute should reference the id(s) of the view element(s) you wish to re-render.
Specify multiple elements to re-render by separating them with a comma delimiter.
</para>
<para>
Such partial rendering is often used with events signaled by Ajax to update a specific zone of the view.
</para>
</sect2>
</sect1>
<sect1 id="view-messages">
<title>Working with messages</title>