### [](#d5e1065)6.6.2. Handling a business exception with a MultiAction
### 6.6.2. Handling a business exception with a MultiAction
The following example is functionally equivlant to the last, but implemented as a MultiAction instead of a POJO action.
The MultiAction requires its action methods to be of the signature `Event ${methodName}(RequestContext)`, providing stronger type safety, while a POJO action allows for more freedom.
...
...
@@ -230,16 +230,16 @@ public Event makeBooking(RequestContext context) {
```
### [](#d5e1071)6.6.3. Using an exception-handler element
### 6.6.3. Using an exception-handler element
In general it is recommended to catch exceptions in actions and return result
events that drive standard transitions, it is also possible to add an`exception-handler` sub-element to any state type with a`bean` attribute referencing a bean of type`FlowExecutionExceptionHandler`. This is an advanced
option that if used incorrectly can leave the flow execution in an invalid state.
Consider the build-in `TransitionExecutingFlowExecutionExceptionHandler`as example of a correct implementation.
## [](#action-examples)6.7. Other Action execution examples
## 6.7. Other Action execution examples
### [](#action-on-start)6.7.1. on-start
### 6.7.1. on-start
The following example shows an action that creates a new Booking object by invoking a method on a service:
...
...
@@ -260,7 +260,7 @@ The following example shows an action that creates a new Booking object by invok
```
### [](#action-on-state-entry)6.7.2. on-entry
### 6.7.2. on-entry
The following example shows a state entry action that sets the special `fragments` variable that causes the view-state to render a partial fragment of its view:
...
...
@@ -273,7 +273,7 @@ The following example shows a state entry action that sets the special `fragment
```
### [](#action-on-state-exit)6.7.3. on-exit
### 6.7.3. on-exit
The following example shows a state exit action that releases a lock on a record being edited:
...
...
@@ -293,7 +293,7 @@ The following example shows a state exit action that releases a lock on a record
```
### [](#on-end)6.7.4. on-end
### 6.7.4. on-end
The following example shows the equivalent object locking behavior using flow start and end actions:
...
...
@@ -324,7 +324,7 @@ The following example shows the equivalent object locking behavior using flow st
```
### [](#action-on-render)6.7.5. on-render
### 6.7.5. on-render
The following example shows a render action that loads a list of hotels to display before the view is rendered:
...
...
@@ -341,7 +341,7 @@ The following example shows a render action that loads a list of hotels to displ
```
### [](#action-on-transition)6.7.6. on-transition
### 6.7.6. on-transition
The following example shows a transition action adds a subflow outcome event attribute to a collection:
...
...
@@ -354,7 +354,7 @@ The following example shows a transition action adds a subflow outcome event att
```
### [](#named-actions)6.7.7. Named actions
### 6.7.7. Named actions
The following example shows how to execute a chain of actions in an action-state.
The name of each action becomes a qualifier for the action's result event.
...
...
@@ -374,7 +374,7 @@ The name of each action becomes a qualifier for the action's result event.
In this example, the flow will transition to `showResults` when `thingTwo`completes successfully.
Sometimes an Action needs to stream a custom response back to the client.
An example might be a flow that renders a PDF document when handling a print event.
...
...
@@ -405,7 +405,7 @@ public class PrintBoardingPassAction extends AbstractAction {
In this example, when the print event is raised the flow will call the printBoardingPassAction.
The action will render the PDF then mark the response as complete.
### [](#file-upload)6.7.9. Handling File Uploads
### 6.7.9. Handling File Uploads
Another common task is to use Web Flow to handle multipart file uploads in combination with Spring MVC's`MultipartResolver`. Once the resolver is set up correctly [as described here](http://static.springsource.org/spring/docs/2.5.x/reference/mvc.html#mvc-multipart) and the submitting
HTML form is configured with `enctype="multipart/form-data"`, you can easily handle the file upload in a
It shows how to implement flows using the flow definition language.
By the end of this chapter you should have a good understanding of language constructs, and be capable of authoring a flow definition.
## [](#flow-overview)3.2. What is a flow?
## 3.2. What is a flow?
A flow encapsulates a reusable sequence of steps that can execute in different contexts.
Below is a [Garrett Information Architecture](http://www.jjg.net/ia/visvocab/) diagram illustrating a reference to a flow that encapsulates the steps of a hotel booking process:
...
...
@@ -15,7 +15,7 @@ Below is a [Garrett Information Architecture](http://www.jjg.net/ia/visvocab/) d
Site Map illustrating a reference to a flow
## [](#flow-makeup)3.3. What is the makeup of a typical flow?
## 3.3. What is the makeup of a typical flow?
In Spring Web Flow, a flow consists of a series of steps called "states".
Entering a state typically results in a view being displayed to the user.
...
...
@@ -28,14 +28,14 @@ The example below shows the structure of the book hotel flow referenced in the p
Flow diagram
## [](#flow-authoring)3.4. How are flows authored?
## 3.4. How are flows authored?
Flows are authored by web application developers using a simple XML-based flow definition language.
The next steps of this guide will walk you through the elements of this language.
## [](#essential-flow-elements)3.5. Essential language elements
## 3.5. Essential language elements
### [](#flow-element)3.5.1. flow
### 3.5.1. flow
Every flow begins with the following root element:
...
...
@@ -53,7 +53,7 @@ Every flow begins with the following root element:
All states of the flow are defined within this element.
The first state defined becomes the flow's starting point.
### [](#view-state-element)3.5.2. view-state
### 3.5.2. view-state
Use the `view-state` element to define a step of the flow that renders a view:
...
...
@@ -65,7 +65,7 @@ Use the `view-state` element to define a step of the flow that renders a view:
By convention, a view-state maps its id to a view template in the directory where the flow is located.
For example, the state above might render `/WEB-INF/hotels/booking/enterBookingDetails.xhtml`if the flow itself was located in the `/WEB-INF/hotels/booking` directory.
### [](#transition-element)3.5.3. transition
### 3.5.3. transition
Use the `transition` element to handle events that occur within a state:
...
...
@@ -78,7 +78,7 @@ Use the `transition` element to handle events that occur within a state:
These transitions drive view navigations.
### [](#end-state-element)3.5.4. end-state
### 3.5.4. end-state
Use the `end-state` element to define a flow outcome:
...
...
@@ -89,7 +89,7 @@ Use the `end-state` element to define a flow outcome:
When a flow transitions to a end-state it terminates and the outcome is returned.
### [](#checkpoint-essential-language-elements)3.5.5. Checkpoint: Essential language elements
### 3.5.5. Checkpoint: Essential language elements
With the three elements `view-state`, `transition`, and `end-state`, you can quickly express your view navigation logic.
Teams often do this before adding flow behaviors so they can focus on developing the user interface of the application with end users first.
...
...
@@ -119,7 +119,7 @@ Below is a sample flow that implements its view navigation logic using these ele
```
## [](#flow-actions)3.6. Actions
## 3.6. Actions
Most flows need to express more than just view navigation logic.
Typically they also need to invoke business services of the application or other actions.
...
...
@@ -141,7 +141,7 @@ Within a flow, there are several points where you can execute actions. These poi
Actions are defined using a concise expression language. Spring Web Flow uses the Unified EL by default.
The next few sections will cover the essential language elements for defining actions.
### [](#evaluate-element)3.6.1. evaluate
### 3.6.1. evaluate
The action element you will use most often is the `evaluate` element.
Use the `evaluate` element to evaluate an expression at a point within your flow.
...
...
@@ -153,7 +153,7 @@ For example:
```
#### [](#evaluate-element-result)Assigning an evaluate result
#### Assigning an evaluate result
If the expression returns a value, that value can be saved in the flow's data model called `flowScope`:
...
...
@@ -162,7 +162,7 @@ If the expression returns a value, that value can be saved in the flow's data mo
```
#### [](#evaluate-element-result-type)Converting an evaluate result
#### Converting an evaluate result
If the expression returns a value that may need to be converted, specify the desired type using the `result-type` attribute:
...
...
@@ -172,7 +172,7 @@ If the expression returns a value that may need to be converted, specify the des
|See the Web Flow XML schema for a complete listing of those XML attributes that accept standard expressions and those that accept template expressions.<br/>You can also use F2 in Eclipse (or equivalent shortcut in other IDEs) to access available documentation when typing out specific flow definition attributes.| |
## [](#el-language-choices)4.2. EL Implementations
## 4.2. EL Implementations
### [](#el-spring-el)4.2.1. Spring EL
### 4.2.1. Spring EL
Web Flow uses the [Spring Expression Language](https://docs.spring.io/spring/docs/current/spring-framework-reference/html/expressions.html)(Spring EL).
Spring EL was created to provide a single, well-supported expression language for use across all the products in the Spring portfolio.
It is distributed as a separate jar `org.springframework.expression` in the Spring Framework.
### [](#el-unified-el)4.2.2. Unified EL
### 4.2.2. Unified EL
Use of [Unified EL](https://en.wikipedia.org/wiki/Unified_Expression_Language)also implies a dependency on `el-api` although that is typically *provided*by your web container.
Although Spring EL is the default and recommended expression language to use,
...
...
@@ -100,7 +100,7 @@ Note that if your application is registering custom converters it's important to
```
## [](#el-portability)4.3. EL portability
## 4.3. EL portability
In general, you will find Spring EL and Unified EL to have a very similar syntax.
...
...
@@ -119,7 +119,7 @@ There are some minor changes to keep in mind when upgrading to Spring EL from Un
For more information on Spring EL syntax please refer to the [Language Reference](http://static.springsource.org/spring/docs/3.0.x/spring-framework-reference/html/expressions.html#expressions-language-ref) section in the Spring Documentation.
## [](#el-variables)4.4. Special EL variables
## 4.4. Special EL variables
There are several implicit variables you may reference from within a flow.
These variables are discussed in this section.
...
...
@@ -165,7 +165,7 @@ However when setting an existing variable such as "searchCriteria" in the exampl
The following is the list of implicit variables you can reference within a flow definition:
### [](#el-variable-flowScope)4.4.1. flowScope
### 4.4.1. flowScope
Use `flowScope` to assign a flow variable.
Flow scope gets allocated when a flow starts and destroyed when the flow ends. With the default
...
...
@@ -176,7 +176,7 @@ implementation, any objects stored in flow scope need to be Serializable.
```
### [](#el-variable-viewScope)4.4.2. viewScope
### 4.4.2. viewScope
Use `viewScope` to assign a view variable.
View scope gets allocated when a `view-state` enters and destroyed when the state exits.
...
...
@@ -191,7 +191,7 @@ default implementation, any objects stored in view scope need to be Serializable
|The intent for flow-level inheritance is to define common states to be<br/>added to and shared among multiple flow definitions while the intent<br/>for state-level inheritance is to extend from and merge with a single<br/>parent state. Flow-level inheritance is a good fit for composition<br/>and multiple inheritance but at the state level you can still only<br/>inherit from a single parent state.| |
|Paths to external resources in the parent flow should be absolute.<br/>Relative paths will break when the two flows are merged unless the parent and child flow are in the same directory.<br/>Once merged, all relative paths in the parent flow will become relative to the child flow.| |
### [](#flow-inheritance-algorithm-mergeable)9.5.1. Mergeable Elements
### 9.5.1. Mergeable Elements
If the elements are of the same type and their keyed attribute are identical, the content of the parent element will be merged with the child element.
The merge algorithm will continue to merge each sub-element of the merging parent and child.
...
...
@@ -124,7 +124,7 @@ Mergeable elements are:
* view-state: id
### [](#flow-inheritance-nonmergeable)9.5.2. Non-mergeable Elements
Many modify data shared by multiple users and therefore require transactional data access properties.
...
...
@@ -12,7 +12,7 @@ Apart from flow-managed persistence, there is the pattern of fully encapsulating
In that case, the web layer does not get involved with persistence, instead it works entirely with detached objects that are passed to and returned by your service layer.
This chapter will focus on the flow-managed persistence, exploring how and when to use this feature.
This pattern creates a `PersistenceContext` in `flowScope` on flow startup,
uses that context for data access during the course of flow execution, and commits changes made to persistent entities at the end.
...
...
@@ -67,7 +67,7 @@ Reference this EntityManager at anytime from within your flow by using the speci
In addition, any data access that occurs using a Spring managed data access object will use this EntityManager automatically.
Such data access operations should always execute non transactionally or in read-only transactions to maintain isolation of intermediate edits.
## [](#flow-managed-persistence-propagation)7.3. Flow Managed Persistence And Sub-Flows
## 7.3. Flow Managed Persistence And Sub-Flows
A flow managed `PersistenceContext` is automatically extended
(propagated) to subflows assuming the subflow also has the `<perstistence-context/>`variable. When a subflow re-uses the `PersistenceContext` started by its parent it ignores
The `attributes` attribute is a comma separated list of Spring Security authorization attributes.
Often, these are specific security roles.
...
...
@@ -52,7 +52,7 @@ The attributes are compared against the user's granted attributes by a Spring Se
By default, a role based access decision manager is used to determine if the user is allowed access.
This will need to be overridden if your application is not using authorization roles.
### [](#flow-security-secured-element-match)8.3.2. Matching type
### 8.3.2. Matching type
There are two types of matching available: `any` and `all`.
Any, allows access if at least one of the required security attributes is granted to the user.
...
...
@@ -68,7 +68,7 @@ If not defined, the default value is `any`.
The `match` attribute will only be respected if the default access decision manager is used.
## [](#flow-security-listener)8.4. The SecurityFlowExecutionListener
## 8.4. The SecurityFlowExecutionListener
Defining security rules in the flow by themselves will not protect the flow execution.
A `SecurityFlowExecutionListener` must also be defined in the webflow configuration and applied to the flow executor.
...
...
@@ -89,7 +89,7 @@ If access is denied to a portion of the application an `AccessDeniedException` w
This exception will later be caught by Spring Security and used to prompt the user to authenticate.
It is important that this exception be allowed to travel up the execution stack uninhibited, otherwise the end user may not be prompted to authenticate.
## [](#flow-security-configuration)8.5. Configuring Spring Security
## 8.5. Configuring Spring Security
Spring Security has robust configuration options available.
As every application and environment has its own security requirements, the [Spring Security reference documentation](http://static.springframework.org/spring-security/site/reference.html) is the best place to learn the available options.
...
...
@@ -111,7 +111,7 @@ As every application and environment has its own security requirements, the [Spr
Both the `booking-faces` and `booking-mvc` sample applications are configured to use Spring Security.
Configuration is needed at both the Spring and web.xml levels.
### [](#flow-security-configuration-spring)8.5.1. Spring configuration
### 8.5.1. Spring configuration
The Spring configuration defines `http` specifics (such as protected URLs and login/logout mechanics) and the `authentication-provider`.
For the sample applications, a local authentication provider is configured.
...
...
@@ -141,7 +141,7 @@ For the sample applications, a local authentication provider is configured.
## [](#manual-overview)1.1. What this guide covers
## 1.1. What this guide covers
This guide covers all aspects of Spring Web Flow.
It covers implementing flows in end-user applications and working with the feature set.
It also covers extending the framework and the overall architectural model.
## [](#system-requirements)1.2. What Web Flow requires to run
## 1.2. What Web Flow requires to run
Java 1.8 or higher.
Spring 5.0 or higher.
## [](#resources)1.3. Resources
## 1.3. Resources
You can ask questions and interact on StackOverflow using the designated tags,
see [Spring at StackOverflow](https://spring.io/questions).
...
...
@@ -22,7 +22,7 @@ Report bugs and make requests using the[Spring Issue Tracker](https://jira.sprin
Submit pull requests and work with the source code ,
see [Web Flow on Github](https://github.com/spring-projects/spring-webflow).
## [](#jars-mvn-central)1.4. How to access Web Flow artifacts from Maven Central
## 1.4. How to access Web Flow artifacts from Maven Central
Each jar in the Web Flow distribution is available in the [Maven Central Repository](https://search.maven.org).
This allows you to easily integrate Web Flow into your application if you are already using Maven as the
...
...
@@ -53,12 +53,12 @@ If using JavaServer Faces, declare the following dependency in your pom
```
## [](#d5e66)1.5. How to access nightly builds and milestone releases
## 1.5. How to access nightly builds and milestone releases
Nightly snapshots of Web Flow development branches are available using Maven.
These snapshot builds are useful for testing out fixes you depend on in advance of the next release, and provide a convenient way for you to provide feedback about whether a fix meets your needs.
### [](#d5e69)1.5.1. Accessing snapshots and milestones with Maven
### 1.5.1. Accessing snapshots and milestones with Maven
For milestones and snapshots you'll need to use the SpringSource repository.
Add the following repository to your Maven pom.xml:
The first step is to route requests to the`DispatcherServlet` in the `web.xml` file. In this
example, we map all URLs that begin with `/spring/` to the
...
...
@@ -68,7 +68,7 @@ web.xml:
```
## [](#spring-faces-webflow-config)13.3. Configuring Web Flow for use with JSF
## 13.3. Configuring Web Flow for use with JSF
This section explains how to configure Web Flow with JSF.
Both Java and XML style configuration are supported.
...
...
@@ -171,7 +171,7 @@ initializes itself with a `JsfAjaxHandler` instead of the`SpringJavaSciprtAjaxHa
When using Java config, the `AbstractFacesFlowConfiguration`base class automatically registers `JsfResourceRequestHandler`so there is nothing further to do.
## [](#spring-faces-managed-beans)13.4. Replacing the JSF Managed Bean Facility
## 13.4. Replacing the JSF Managed Bean Facility
When using JSF with Spring Web Flow you can completely replace the
JSF managed bean facility with a combination of Web Flow managed variables
...
...
@@ -195,7 +195,7 @@ flow, and conversation scopes. These scopes are seamlessly integrated
through JSF variable resolvers and work the same in all JSF
applications.
### [](#spring-faces-flow-variables)13.4.1. Using Flow Variables
### 13.4.1. Using Flow Variables
The easiest and most natural way to declare and manage the model
is through the use of [flow
...
...
@@ -237,7 +237,7 @@ To define a view instance variable, you can use the`var` element inside a `view-
```
### [](#spring-faces-spring-beans)13.4.2. Using Scoped Spring Beans
### 13.4.2. Using Scoped Spring Beans
Though defining autowired flow instance variables provides nice
modularization and readability, occasions may arise where you want to
...
...
@@ -255,7 +255,7 @@ be fully initialized until it is first accessed via an EL expression.
This sort of lazy instantiation via EL is quite similar to how JSF
managed beans are typically allocated.
### [](#faces-manipulating-model)13.4.3. Manipulating The Model
### 13.4.3. Manipulating The Model
The need to initialize the model before view rendering (such as by
loading persistent entities from a database) is quite common, but JSF by
...
...
@@ -296,7 +296,7 @@ component:
```
### [](#faces-data-model-implementations)13.4.4. Data Model Implementations
### 13.4.4. Data Model Implementations
In the example above result-type="dataModel" results in the
wrapping of List\<Booking\> with custom`DataModel` type. The custom`DataModel` provides extra conveniences such as
...
...
@@ -325,7 +325,7 @@ causes the `DataModelConverter` to be used. The
converter then wraps the given List with an instance of`OneSelectionTrackingListDataModel`. To use the`ManySelectionTrackingListDataModel` you will need
to register your own custom converter.
## [](#spring-faces-event-handling)13.5. Handling JSF Events With Spring Web Flow
## 13.5. Handling JSF Events With Spring Web Flow
Spring Web Flow allows you to handle JSF action events in a
decoupled way, requiring no direct dependencies in your Java code on JSF
...
...
@@ -336,7 +336,7 @@ manipulated in wiring up events (JSF view templates and SWF flow
definitions) are instantly refreshable without requiring a build and
The next logical level beyond in-page events are events that
require navigation to another view, with some manipulation of the model
...
...
@@ -432,7 +432,7 @@ Here the "select" event is handled by pushing the currently
selected hotel instance from the DataTable into flow scope, so that it
may be referenced by the "reviewHotel" `view-state` .
### [](#spring-faces-model-validation)13.5.3. Performing Model Validation
### 13.5.3. Performing Model Validation
JSF provides useful facilities for validating input at field-level
before changes are applied to the model, but when you need to then
...
...
@@ -467,7 +467,7 @@ validation method on the booking instance, passing the generic`MessageContext` i
The messages can then be displayed along with any other JSF messages
with the `h:messages` component,
### [](#spring-faces-ajax-events-jsf2)13.5.4. Handling Ajax Events In JSF
### 13.5.4. Handling Ajax Events In JSF
JSF provides built-in support for sending Ajax requests and
performing partial processing and rendering on the server-side. You can
...
...
@@ -492,7 +492,7 @@ action:
```
## [](#spring-faces-embedded-mode)13.6. Embedding a Flow On a Page
## 13.6. Embedding a Flow On a Page
By default when a flow enters a view state, it executes a
client-side redirect before rendering the view. This approach is known as
...
...
@@ -540,7 +540,7 @@ mvn package
The specific example you need to look at is under the "Advanced Ajax"
tab and is called "Top Flow with Embedded Sub-Flow".
## [](#spring-faces-redirect-in-same-state)13.7. Redirect In Same State
## 13.7. Redirect In Same State
By default Web Flow does a client-side redirect even it it remains in the same view state as long as the current request is not an Ajax request.
This is quite useful after form validation failures for example.
...
...
@@ -563,7 +563,7 @@ However if you experience this issue you can disable client-side redirects withi
```
## [](#spring-faces-file-upload)13.8. Handling File Uploads with JSF
## 13.8. Handling File Uploads with JSF
Most JSF component providers include some form of 'file upload' component. Generally when working
with these components JSF must take complete control of parsing multi-part requests and Spring MVC's`MultipartResolver` cannot be used.
...
...
@@ -571,7 +571,7 @@ with these components JSF must take complete control of parsing multi-part reque
Spring Web Flow has been tested with file upload components from PrimeFaces. Check the
documentation of your JSF component library for other providers to see how to configure file upload.
### [](#d5e1950)13.8.1. File Uploads with PrimeFaces
### 13.8.1. File Uploads with PrimeFaces
PrimeFaces provides a `<p:fileUpload>` component for uploading files. In order
to use the component you need to configure the `org.primefaces.webapp.filter.FileUploadFilter`servlet filter. The filter needs to be configured against Spring MVC's`DispatcherServlet` in your `web.xml`:
...
...
@@ -595,7 +595,7 @@ to use the component you need to configure the `org.primefaces.webapp.filter.Fil
For more details refer to the[PrimeFaces documentation](http://primefaces.org/documentation.html).
## [](#spring-faces-security-taglib)13.9. Using the Spring Security Facelets Tag Library
## 13.9. Using the Spring Security Facelets Tag Library
To use the library you'll need to create a `.taglib.xml`file and register it in `web.xml`.
...
...
@@ -699,7 +699,7 @@ other attribute of any JSF component:
Spring Javascript's client-side Ajax response handling is built upon the notion of receiving "fragments" back from the server.
These fragments are just standard HTML that is meant to replace portions of the existing page.
...
...
@@ -208,7 +208,7 @@ Spring Javascript's Ajax remoting functionality is built upon the notion that th
Ajax request should not differ from a standard browser request, thus no special knowledge of an Ajax request
is needed directly in the code and the same hanlder can be used for both styles of request.
### [](#custom-ajax-handler)12.5.1. Providing a Library-Specific AjaxHandler
### 12.5.1. Providing a Library-Specific AjaxHandler
The key interface for integrating various Ajax libraries with the Ajax-aware behavior of Web Flow (such as not redirecting for a
partial page update) is `org.springframework.js.AjaxHandler`. A `SpringJavascriptAjaxHandler` is configured by default that is able to
...
...
@@ -216,7 +216,7 @@ detect an Ajax request submitted via the Spring JS client-side API and can respo
order to integrate a different Ajax library (be it a pure JavaScript library, or a higher-level abstraction such as an Ajax-capable JSF
component library), a custom `AjaxHandler` can be injected into the `FlowHandlerAdapter` or `FlowController`.
### [](#spring-js-ajax-mvc)12.5.2. Handling Ajax Requests with Spring MVC Controllers
### 12.5.2. Handling Ajax Requests with Spring MVC Controllers
In order to handle Ajax requests with Spring MVC controllers, all that is needed is the configuration of
the provided Spring MVC extensions in your Spring application context for rendering the partial response
...
...
@@ -247,7 +247,7 @@ The fragments correspond to individual attributes of a Tiles view definition. Fo
An Ajax request could specify the "body", "hotelSearchForm" or "bookingsTable" to be rendered as fragments in the request.
### [](#spring-js-ajax-mvc-webflow)12.5.3. Handling Ajax Requests with Spring MVC + Spring Web Flow
### 12.5.3. Handling Ajax Requests with Spring MVC + Spring Web Flow
Spring Web Flow handles the optional rendering of fragments directly in the flow definition language through use of the `render` element.
The benefit of this approach is that the selection of fragments is completely decoupled from client-side code, such that no special parameters need to be passed with the request the way they
Web Flow 2 maps selected view identifiers to files located within
the flow's working directory unless otherwise specified. For existing
...
...
@@ -260,7 +260,7 @@ Spring MVC's native BeanWrapper by setting the`useSpringBinding` flag to true. T
using the Unified EL for view-to-model data binding. See the
JavaDoc API of this class for more information.
## [](#spring-mvc-resuming-on-event)11.6. Signaling an event from a View
## 11.6. Signaling an event from a View
When a flow enters a view-state it pauses, redirects the user to its
execution URL, and waits for a user event to resume. Events are generally
...
...
@@ -270,7 +270,7 @@ use. This section shows how to trigger events from HTML-based views
generated by templating engines such as JSP, Velocity, or
Freemarker.
### [](#webflow-event-named-html-button)11.6.1. Using a named HTML button to signal an event
### 11.6.1. Using a named HTML button to signal an event
The example below shows two buttons on the same form that signal`proceed` and `cancel` events when clicked,
respectively.
...
...
@@ -287,7 +287,7 @@ as the event id. So in this example, submitting`_eventId_proceed` becomes `proce
should be considered when there are several different events that can be
signaled from the same form.
### [](#webflow-event-hidden-parameter)11.6.2. Using a hidden HTML form parameter to signal an event
### 11.6.2. Using a hidden HTML form parameter to signal an event
The example below shows a form that signals the`proceed` event when submitted:
...
...
@@ -301,7 +301,7 @@ Here, Web Flow simply detects the special `_eventId`parameter and uses its value
considered when there is one event that can be signaled on the
form.
### [](#webflow-event-link)11.6.3. Using a HTML link to signal an event
### 11.6.3. Using a HTML link to signal an event
The example below shows a link that signals the`cancel` event when activated:
...
...
@@ -318,7 +318,7 @@ implementation simply looks for a request parameter named`_eventId`. If no `_eve
the view will look for a parameter that starts with`_eventId_` and will use the remaining substring as the event
id. If neither cases exist, no flow event is triggered.
## [](#spring-mvc-embedded-flow)11.7. Embedding A Flow On A Page
## 11.7. Embedding A Flow On A Page
By default when a flow enters a view state, it executes a
client-side redirect before rendering the view. This approach is known as
...
...
@@ -352,7 +352,7 @@ only needs to be passed when launching the flow. Your only other concern is
to use Ajax requests and to render only the content required to update
the portion of the page displaying the flow.
### [](#spring-mvc-embedded-flow-alternatives)11.7.1. Embedded Mode Vs Default Redirect Behavior
### 11.7.1. Embedded Mode Vs Default Redirect Behavior
By default Web Flow does a client-side redirect upon entering every view state.
However if you remain in the same view state -- for example a transition without a "to" attribute -- during an Ajax request there will not be a client-side redirect.
...
...
@@ -362,7 +362,7 @@ However transitions to a new view state are always followed with a client-side r
That makes it impossible to embed a flow on a page or within a modal dialog and execute more than one view state without causing a full-page refresh.
Hence if your use case requires embedding a flow you can launch it in "embedded" mode.
If you'd like to see examples of a flow embedded on a page and within
a modal dialog please refer to the webflow-showcase project. You can check out
...
...
@@ -377,7 +377,7 @@ mvn package
# import into Eclipse
```
## [](#spring-mvc-flash-output)11.8. Saving Flow Output to MVC Flash Scope
## 11.8. Saving Flow Output to MVC Flash Scope
Flow output can be automatically saved to MVC flash scope when an `end-state`performs an internal redirect. This is particularly useful when displaying a summary
screen at the end of a flow. For backwards compatibility this feature is disabled by
In the above example, suppose you had flows located in `/user/login`, `/user/registration`, `/hotels/booking`, and `/flights/booking` directories within `WEB-INF`,
you'd end up with flow ids of `user/login`, `user/registration`, `hotels/booking`, and `flights/booking`, respectively.
Use the `conversion-service` attribute to customize the `ConversionService` used by the Web Flow system.
Type conversion is used to convert from one type to another when required during flow execution such as when processing request parameters, invoking actions, and so on.
...
...
@@ -377,12 +377,12 @@ Many common object types such as numbers, classes, and enums are supported.
However you'll probably need to provide your own type conversion and formatting logic for custom data types.
Please read [Section 5.7, “Performing type conversion”](views.html#view-type-conversion) for important information on how to provide custom type conversion logic.
Use the `on-render` element to execute one or more actions before view rendering.
Render actions are executed on the initial render as well as any subsequent refreshes, including any partial re-renderings of the view.
...
...
@@ -122,7 +122,7 @@ Render actions are executed on the initial render as well as any subsequent refr
```
## [](#view-model)5.6. Binding to a model
## 5.6. Binding to a model
Use the `model` attribute to declare a model object the view binds to.
This attribute is typically used in conjunction with views that render data controls, such as forms.
...
...
@@ -145,13 +145,13 @@ Specifying a `model` triggers the following behavior when a view event occurs:
For a flow event to be generated that can drive a view state transition, model binding must complete successfully.
If model binding fails, the view is re-rendered to allow the user to revise their edits.
## [](#view-type-conversion)5.7. Performing type conversion
## 5.7. Performing type conversion
When request parameters are used to populate the model (commonly referred to as data binding), type conversion is required to parse String-based request parameter values before setting target model properties.
Default type conversion is available for many common Java types such as numbers, primitives, enums, and Dates.
Users also have the ability to register their own type conversion logic for user-defined types, and to override the default Converters.
### [](#converter-options)5.7.1. Type Conversion Options
### 5.7.1. Type Conversion Options
Starting with version 2.1 Spring Web Flow uses the [type conversion](http://static.springsource.org/spring/docs/3.0.x/spring-framework-reference/html/validation.html#core-convert) and [formatting](http://static.springsource.org/spring/docs/3.0.x/spring-framework-reference/html/validation.html#format) system introduced in Spring 3 for nearly all type conversion needs.
Previously Web Flow applications used a type conversion mechanism that was different from the one in Spring MVC, which relied on the `java.beans.PropertyEditor` abstraction.
...
...
@@ -159,7 +159,7 @@ Spring 3 offers a modern type conversion alternative to PropertyEditors that was
Hence Web Flow users should find it natural to work with the new Spring 3 type conversion.
Another obvious and very important benefit of this change is that a single type conversion mechanism can now be used across Spring MVC And Spring Web Flow.
### [](#converter-upgrade-to-spring-3)5.7.2. Upgrading to Spring 3 Type Conversion And Formatting
### 5.7.2. Upgrading to Spring 3 Type Conversion And Formatting
What does this practically mean for existing applications?
Existing applications are likely registering their own converters of type `org.springframework.binding.convert.converters.Converter` through a sub-class of `DefaultConversionService` available in Spring Binding.
...
...
@@ -199,7 +199,7 @@ Instead Web Flow now relies on the default type converters and formatters in Spr
In summary the Spring 3 type conversion and formatting is now used almost exclusively in Web Flow.
Although existing applications will work without any changes, we encourage moving towards unifying the type conversion needs of Spring MVC and Spring Web Flow parts of applications.
### [](#converter-configuration)5.7.3. Configuring Type Conversion and Formatting
### 5.7.3. Configuring Type Conversion and Formatting
In Spring MVC an instance of a `FormattingConversionService` is created automatically through the custom MVC namespace:
...
...
@@ -299,7 +299,7 @@ Of course it is also possible to mix and match.
Register new Spring 3 `Formatter` types through the "applicationConversionService".
Register existing Spring Binding `Converter` types through the "defaultConversionService".
### [](#converter-working-with)5.7.4. Working With Spring 3 Type Conversion And Formatting
### 5.7.4. Working With Spring 3 Type Conversion And Formatting
An important concept to understand is the difference between type converters and formatters.
...
...
@@ -315,14 +315,14 @@ Web developers will find the `Formatter` interface most relevant because it fits
|An important point to be made is that Object-to-Object conversion is a generalization of the more specific Object-to-String conversion.<br/>In fact in the end `Formatters` are reigstered as `GenericConverter` types with Spring's `GenericConversionService` making them equal to any other converter.| |
One of the best features of the new type conversion is the ability to use annotations for a better control over formatting in a concise manner.
Annotations can be placed on model attributes and on arguments of @Controller methods that are mapped to requests.
Out of the box Spring provides two annotations `NumberFormat` and `DateTimeFormat` but you can create your own and have them registered along with the associated formatting logic.
You can see examples of the `DateTimeFormat` annotation in the [Spring Travel](https://src.springframework.org/svn/spring-samples/travel) and in the [Petcare](https://src.springframework.org/svn/spring-samples/petcare) along with other samples in the [Spring Samples](https://src.springframework.org/svn/spring-samples) repository.
### [](#converter-dates)5.7.6. Working With Dates
### 5.7.6. Working With Dates
The `DateTimeFormat` annotation implies use of [Joda Time](http://joda-time.sourceforge.net/).
If that is present on the classpath the use of this annotation is enabled automatically.
...
...
@@ -332,7 +332,7 @@ The `DateTimeFormat` annotation on the other hand provides more fine-grained con
For more information on working with Spring 3 type conversion and formatting please refer to the relevant sections of the [Spring documentation](http://static.springsource.org/spring/docs/3.0.x/spring-framework-reference/html/index.html).
## [](#view-bind)5.8. Suppressing binding
## 5.8. Suppressing binding
Use the `bind` attribute to suppress model binding and validation for particular view events.
The following example suppresses binding when the `cancel` event occurs:
...
...
@@ -345,7 +345,7 @@ The following example suppresses binding when the `cancel` event occurs:
There are two ways to perform model validation programatically.
The first is to implement validation logic in your model object.
The second is to implement an external `Validator`.
Both ways provide you with a `ValidationContext` to record error messages and access information about the current user.
#### [](#view-validation-programmatic-validate-method)Implementing a model validate method
#### Implementing a model validate method
Defining validation logic in your model object is the simplest way to validate its state.
Once such logic is structured according to Web Flow conventions, Web Flow will automatically invoke that logic during the view-state postback lifecycle.
...
...
@@ -536,7 +536,7 @@ An example of such a view-state is shown below:
Any number of validation methods are defined. Generally, a flow edits a model over a series of views. In that case, a validate method would be defined
for each view-state where validation needs to run.
#### [](#view-validation-programmatic-validator)Implementing a Validator
#### Implementing a Validator
The second way is to define a separate object, called a *Validator*, which validates your model object.
To do this, first create a class whose name has the pattern ${model}Validator, where `${model}` is the capitialized form of the model expression, such as `booking`.
...
...
@@ -570,7 +570,7 @@ Validators must be registered as Spring beans employing the naming convention `$
In the example above, Spring 2.5 classpath-scanning would detect the `@Component` and automatically register it as a bean with the name `bookingValidator`.
Then, anytime the `booking` model needs to be validated, this `bookingValidator` instance would be invoked for you.
This release provides an upgrade path to Spring Framework 5 that in turn requires
Java 8+, Servlet 3.1, Hibernate 5, Tiles 3. See the[Spring Framework wiki](https://github.com/spring-projects/spring-framework/wiki/What%27s-New-in-Spring-Framework-5.x)for more details. The [samples repository](https://github.com/spring-projects/spring-webflow-samples)has been upgraded to Spring Web Flow 2.5.
Web Flow now supports a Java-based alternative for its system configuration.
See the updated [Chapter 10, *System Setup*](system-setup.html).
Also see the[booking-mvc](https://github.com/spring-projects/spring-webflow-samples/tree/master/booking-mvc) and[booking-faces](https://github.com/spring-projects/spring-webflow-samples/tree/master/booking-faces)samples that have been updated to use all Java config.
### [](#whatsnew-swf-mvcflash)2.2.2. Spring MVC Flash Scope Integration
### 2.2.2. Spring MVC Flash Scope Integration
When a flow ends it can now redirect to a Spring MVC controller after saving
attributes in Spring MVC's flash scope for the controller to access.
See [Section 11.8, “Saving Flow Output to MVC Flash Scope”](spring-mvc.html#spring-mvc-flash-output).
Java ServerFaces version 1.2 and earlier are no longer supported by Spring Web Flow, if you have not done so already you will need to upgrade to JSF 2.0 or above.
In addition the Spring Faces components that were previously provided with JSF 1.2 for progressive AJAX enhancements have been removed in this release.
See [???]().
### [](#whatsnew-swf-jsf20-portlet)2.2.7. Portlet API 2.0 and JSF 2.0 support
### 2.2.7. Portlet API 2.0 and JSF 2.0 support
The internal Portlet integration introduced in Spring Web Flow 2.2 has been upgraded for JSF 2.0 compatibility.
Some of the more advanced JSF 2.0 features, such as partial state saving, are not supported in a Portlet environment, however, existing application can now upgrade to the minimum required JSF version.
Upgraded projects will need to ensure that the `<faces:resources>` elements is
included as part of their Spring configuration.
### [](#whatsnew-deprecation)2.2.8. Deprecations
### 2.2.8. Deprecations
This release deprecates *Spring.js*. The deprecation includes the entire*spring-js-resources* module including *Spring.js* and*Spring-Dojo.js* and the bundled Dojo and CSS Framework.
Also deprecated is the `SpringJavascriptAjaxHandler`from the *spring-js* module. The rest of *spring-js*,
...
...
@@ -70,9 +70,9 @@ folded into *spring-webflow* in a future release.
OGNL support is now deprecated.
## [](#whatsnew-swf-230)2.3. Spring Web Flow 2.3
## 2.3. Spring Web Flow 2.3
### [](#whatsnew-swf-embedded-flow)2.3.1. Embedding A Flow On A Page
### 2.3.1. Embedding A Flow On A Page
By default Web Flow does a client-side redirect upon entering every view state.
That makes it impossible to embed a flow on a page or within a modal dialog and execute more than one view state without causing a full-page refresh.
...
...
@@ -80,28 +80,28 @@ Web Flow now supports launching a flow in "embedded" mode.
In this mode a flow can transition to other view states without a client-side redirect during Ajax requests.
See [Section 11.7, “Embedding A Flow On A Page”](spring-mvc.html#spring-mvc-embedded-flow) and [Section 13.6, “Embedding a Flow On a Page”](spring-faces.html#spring-faces-embedded-mode).
### [](#whatsnew-jsr303)2.3.2. Support For JSR-303 Bean Validation
### 2.3.2. Support For JSR-303 Bean Validation
Support for the JSR-303 Bean Validation API is now available building on equivalent support available in Spring MVC.
See [Section 5.10, “Validating a model”](views.html#view-validate) for more details.
Starting with Web Flow 2.3 a flow managed `PersistenceContext` is automatically extended (propagated) to sub-flows assuming the subflow also has the feature enabled as well.
See [Section 7.3, “Flow Managed Persistence And Sub-Flows”](flow-managed-persistence.html#flow-managed-persistence-propagation).
The `<flow-execution-repository>` element now provides a conversation-manager attribute accepting a reference to a ConversationManager instance.
### [](#whatsnew-redirect-in-same-state)2.3.6. Redirect In Same State
### 2.3.6. Redirect In Same State
By default Web Flow does a client-side redirect when remaining in the same view state as long as the current request is not an Ajax request.
This is useful after form validation failure.
...
...
@@ -109,7 +109,7 @@ Hitting Refresh or Back won't result in browser warnings. Hence this behavior is
However a new flow execution attribute makes it possible to disable it and that may also be necessary in some cases specific to JSF applications.
See [Section 13.7, “Redirect In Same State”](spring-faces.html#spring-faces-redirect-in-same-state).
### [](#whatsnew-samples)2.3.7. Samples
### 2.3.7. Samples
The process for building the samples included with the distribution has been simplified.
Maven can be used to build all samples in one step.
...
...
@@ -137,11 +137,11 @@ mvn package
```
## [](#whatsnew-swf-220)2.4. Spring Web Flow 2.2
## 2.4. Spring Web Flow 2.2
### [](#whatsnew-jsf2)2.4.1. JSF 2 Support
### 2.4.1. JSF 2 Support
#### [](#d5e180)Comprehensive JSF 2 Support
#### Comprehensive JSF 2 Support
Building on 2.1, Spring Web Flow version 2.2 adds support for core JSF 2 features
The following features that were not supported in 2.1 are now available:
...
...
@@ -158,7 +158,7 @@ fact MyFaces was not as easy to customize with regards to how component state is
We will work with Apache MyFaces to provide this support. In the mean time you will need to use
the `javax.faces.PARTIAL_STATE_SAVING` context parameter in `web.xml`to disable partial state saving with Apache MyFaces.
#### [](#d5e187)Travel Sample With the PrimeFaces Components
#### Travel Sample With the PrimeFaces Components
The main Spring Travel sample demonstrating Spring Web Flow and JSF support
is now built on JSF 2 and components from the PrimeFaces component library.
...
...
@@ -173,22 +173,22 @@ svn co https://src.springframework.org/svn/spring-samples/webflow-primefaces-sho
```
### [](#whatsnew-sec)2.4.2. Spring Security Facelets Tag Library
### 2.4.2. Spring Security Facelets Tag Library
A new Spring Security tag library is available for use with with JSF 2.0 or with JSF 1.2 Facelets views.
It provides an \<authorize\> tag as well as several EL functions.
See [Section 13.9, “Using the Spring Security Facelets Tag Library”](spring-faces.html#spring-faces-security-taglib) for more details.
### [](#whatsnew-versions)2.4.3. Spring JavaScript Updates
### 2.4.3. Spring JavaScript Updates
#### [](#d5e200)Deprecated ResourcesServlet
#### Deprecated ResourcesServlet
Starting with Spring 3.0.4, the Spring Framework includes
a replacement for the ResourcesServlet. Please see
the Spring Framework documentation for details on the custom mvc namespace,
specifically the new["resources"](http://static.springsource.org/spring/docs/3.0.x/spring-framework-reference/html/mvc.html#mvc-static-resources)element.
#### [](#d5e204)Dojo 1.5 and dojox
#### Dojo 1.5 and dojox
The bundled custom Dojo build is upgraded to version 1.5. It now includes dojox.
...
...
@@ -196,7 +196,7 @@ Note that applications are generally encouraged to prepare their own custom
Dojo build for optimized performance depending on what parts of Dojo are
commonly used together. For examples see the[scripts](https://src.springframework.org/svn/spring-webflow/branches/spring-webflow-2.2-maintenance/spring-js-resources/scripts/dojo)used by Spring Web Flow to prepare its own custom Dojo build.
#### [](#d5e209)Two Spring JS artifacts
#### Two Spring JS artifacts
The `spring-js` artifact has been split in two -- the new artifact
(`spring-js-resources`) contains client side resource (.js, .css, etc.) while
虽然将动作代码编写为 POJO 逻辑是最常见的,但还有其他几种动作实现选项。有时你需要编写需要访问流上下文的动作代码。你总是可以调用 POJO 并将 FlowRequestContext 作为 EL 变量传递给它。或者,你可以实现`Action`接口或从`MultiAction`基类进行扩展。当你的操作代码和 Spring Web 流 API 之间具有天然的耦合时,这些选项提供了更强的类型安全性。下面是这些方法的示例。
另一个常见的任务是使用 Web 流结合 Spring MVC 的`MultipartResolver`处理多部分文件上传。一旦正确设置了解析器[如此处所述](http://static.springsource.org/spring/docs/2.5.x/reference/mvc.html#mvc-multipart),并且将提交的 HTML 表单配置为`enctype="multipart/form-data"`,你就可以在转换操作中轻松处理文件上传。
|有关接受标准表达式和接受模板表达式的 XML 属性的完整列表,请参见 Web Flow XML 模式。<br/>你还可以在 Eclipse 中使用 F2(或在其他 IDE 中使用等效的快捷方式)在键入特定的流定义属性时访问可用的文档。| |
## [](#el-language-choices)4.2。EL 实现
## 4.2.EL 实现
### [](#el-spring-el)4.2.1。 Spring El
### 4.2.1. Spring El
Web 流使用[Spring Expression Language](https://docs.spring.io/spring/docs/current/spring-framework-reference/html/expressions.html)( Spring el)。 Spring 创建 EL 是为了提供一种单一的、支持良好的表达式语言,用于在 Spring 产品组合中的所有产品中使用。在 Spring 框架中,它作为一个单独的 JAR`org.springframework.expression`分发。
### [](#el-unified-el)4.2.2。统一 El
### 4.2.2.统一 El
使用[Unified EL](https://en.wikipedia.org/wiki/Unified_Expression_Language)还意味着对`el-api`的依赖,尽管你的 Web 容器通常是*提供*。 Spring 虽然 EL 是默认的和推荐使用的表达式语言,但如果你希望这样做,可以用统一的 EL 替换它。你需要以下 Spring 配置来将`WebFlowELExpressionParser`插入`flow-builder-services`:
...
...
@@ -83,7 +83,7 @@ Web 流使用[Spring Expression Language](https://docs.spring.io/spring/docs/cur
```
## [](#el-portability)4.3。EL 便携性
## 4.3.EL 便携性
通常,你会发现 Spring EL 和 Unified EL 具有非常相似的语法。
...
...
@@ -99,7 +99,7 @@ Web 流使用[Spring Expression Language](https://docs.spring.io/spring/docs/cur
有关 Spring EL 语法的更多信息,请参阅 Spring 文档中的[语言参考](http://static.springsource.org/spring/docs/3.0.x/spring-framework-reference/html/expressions.html#expressions-language-ref)部分。
## [](#el-variables)4.4。特殊 EL 变量
## 4.4.特殊 EL 变量
你可以从流中引用几个隐式变量。这些变量将在本节中讨论。
...
...
@@ -143,7 +143,7 @@ Web 流使用[Spring Expression Language](https://docs.spring.io/spring/docs/cur
就是这样。当你的流开始时,侦听器将在`flowScope`中处理分配一个新的`EntityManager`。通过使用特殊的`persistenceContext`变量,在你的流中随时引用这个 EntityManager。此外,使用 Spring 托管数据访问对象进行的任何数据访问都将自动使用该 EntityManager。这样的数据访问操作应该总是在非事务或只读事务中执行,以保持中间编辑的隔离。
## [](#flow-security-configuration)8.5。配置 Spring 安全性
## 8.5.配置 Spring 安全性
Spring 安全性具有可供选择的健壮配置。由于每个应用程序和环境都有自己的安全需求,因此[Spring Security reference documentation](http://static.springframework.org/spring-security/site/reference.html)是学习可用选项的最佳位置。
`booking-faces`和`booking-mvc`示例应用程序都被配置为使用 Spring 安全性。在 Spring 和 web.xml 级别都需要配置。
### [](#flow-security-configuration-spring)8.5.1。 Spring 配置
### 8.5.1. Spring 配置
Spring 配置定义了`http`细节(例如受保护的 URL 和登录/注销机制)和`authentication-provider`。对于样例应用程序,配置了本地身份验证提供程序。
...
...
@@ -119,7 +119,7 @@ Spring 配置定义了`http`细节(例如受保护的 URL 和登录/注销机
Spring Web Flow 提供了一种 JSF 集成,允许你使用带有 Spring Web Flow 控制器的 JSF UI 组件模型。Web Flow 还提供了用于 JSF 环境的 Spring 安全标记库,有关更多详细信息,请参见[Section 13.9, “Using the Spring Security Facelets Tag Library”](spring-faces.html#spring-faces-security-taglib)。
当将 JSF 与 Spring Web 流一起使用时,你可以将 JSF Managed Bean 工具完全替换为 Web 流管理变量和 Spring Managed bean 的组合。它为你提供了对托管对象的生命周期的更多控制,并为域模型的初始化和执行提供了定义良好的挂钩。此外,由于你可能已经在业务层中使用了 Spring,因此它减少了必须维护两个不同的托管 Bean 模型的概念开销。
在进行纯粹的 JSF 开发时,你很快就会发现请求作用域不够长,不足以存储驱动复杂事件驱动视图的会话模型对象。在 JSF 中,通常的选择是开始将事情放入会话范围,在进入应用程序的另一个视图或功能区域之前,需要清理对象,这是一个额外的负担。真正需要的是介于请求和会话范围之间的托管范围。JSF 提供了可以通过 UIViewRoot.getViewMap()以编程方式访问的闪存和视图范围。 Spring Web Flow 提供对 Flash、View、Flow 和 Conversation 范围的访问。这些作用域通过 JSF 变量解析器无缝地集成在一起,并且在所有 JSF 应用程序中都是相同的。
@@ -189,7 +189,7 @@ public class WebFlowConfig extends AbstractFacesFlowConfiguration {
```
### [](#spring-faces-spring-beans)13.4.2。使用范围 Spring bean
### 13.4.2.使用范围 Spring bean
虽然定义 AutoWired 流实例变量提供了很好的模块化和可读性,但可能会出现希望利用 Spring 容器的其他功能的情况,例如 AOP。在这些情况下,你可以在 Spring 应用程序上下文中定义 Bean,并为其提供一个特定的 Web 流范围:
...
...
@@ -200,7 +200,7 @@ public class WebFlowConfig extends AbstractFacesFlowConfiguration {
这种方法的主要区别在于,在通过 EL 表达式首次访问 Bean 之前,不会对 Bean 进行完全初始化。这种通过 EL 的惰性实例化非常类似于 JSF 托管 bean 的典型分配方式。
### [](#faces-manipulating-model)13.4.3。操纵模型
### 13.4.3.操纵模型
在视图呈现之前需要初始化模型(例如通过从数据库加载持久实体)是很常见的,但是 JSF 本身并没有为这种初始化提供任何方便的挂钩。流定义语言通过其[Actions](defining-flows.html#flow-actions)为此提供了一种自然的工具。 Spring Web 流为将一个动作的结果转换为特定于 JSF 的数据结构提供了一些额外的便利。例如:
...
...
@@ -233,7 +233,7 @@ public class WebFlowConfig extends AbstractFacesFlowConfiguration {
Spring 框架提供了一种用于服务静态资源的机制。参见[Spring Framework documentation](https://docs.spring.io/spring/docs/current/spring-framework-reference/web.html#mvc-config-static-resources))。使用新的 \<mvc:resources\>元素,资源请求由`DispatcherSevlet`处理。下面是 XML 中的配置示例(也可以使用 Java 配置):
...
...
@@ -68,7 +68,7 @@ Spring 框架提供了一种用于服务静态资源的机制。参见[Spring Fr
```
## [](#spring-js-includes)12.3。在页面中包括 Spring JavaScript
## 12.3.在页面中包括 Spring JavaScript
Spring JS 的设计使得可以为任何流行的 JavaScript 工具包构建其 API 的实现。 Spring.js 的初始实现建立在 Dojo 工具箱的基础上。
...
...
@@ -88,7 +88,7 @@ Spring JS 的设计使得可以为任何流行的 JavaScript 工具包构建其
```
## [](#spring-js-decorations)12.4。 Spring JavaScript 装饰
## 12.4. Spring JavaScript 装饰
Spring JavaScript 中的一个核心概念是将装饰应用到现有 DOM 节点的概念。这种技术用于逐步增强网页,使网页在功能较差的浏览器中仍能正常工作。使用`addDecoration`方法应用装饰。
...
...
@@ -166,7 +166,7 @@ Spring JavaScript 中的一个核心概念是将装饰应用到现有 DOM 节点
```
## [](#spring-js-ajax)12.5。处理 Ajax 请求
## 12.5.处理 Ajax 请求
Spring JavaScript 的客户端 Ajax 响应处理建立在从服务器接收“碎片”的概念上。这些片段只是标准的 HTML,旨在替换现有页面的部分内容。服务器上所需的关键部分是一种确定需要将完整响应中的哪些部分拉出以进行部分呈现的方法。
...
...
@@ -174,11 +174,11 @@ Spring JavaScript 的客户端 Ajax 响应处理建立在从服务器接收“
Spring JavaScript 的 Ajax 远程处理功能是建立在这样一种理念之上的:Ajax 请求的核心处理代码不应与标准的浏览器请求不同,因此,在代码中不需要直接提供有关 Ajax 请求的特殊知识,并且可以对两种类型的请求使用相同的方法。
### [](#spring-js-ajax-mvc-webflow)12.5.3。用 Spring MVC+ Spring Web 流处理 Ajax 请求
### 12.5.3.用 Spring MVC+ Spring Web 流处理 Ajax 请求
Spring Web 流通过使用`render`元素直接在流定义语言中处理片段的可选呈现。这种方法的好处是,片段的选择与客户端代码完全解耦,这样就不需要以纯 Spring MVC 控制器方法当前必须采用的方式与请求一起传递特殊参数。例如,如果你希望将前面的示例磁贴视图中的“HotelSearchForm”片段呈现为一个富 JavaScript 弹出窗口:
除非另有说明,否则 Web Flow2 将选定的视图标识符映射到位于流的工作目录中的文件。对于现有的 Spring MVC+Web 流应用程序,外部`ViewResolver`可能已经在为你处理此映射。因此,要继续使用该解析器,并避免更改打包现有流视图的方式,请按以下方式配置 Web 流:
...
...
@@ -178,11 +178,11 @@ public class BookingFlowHandler extends AbstractFlowHandler {
MVCViewFactoryCreator 是一个工厂,它允许你配置如何在 Spring Web 流中使用 Spring MVC 视图系统。使用它来配置现有的 viewresolver,以及其他服务,例如定制的 MessageCodesresolver。你还可以通过将`useSpringBinding`标志设置为 true 来启用使用 Spring MVC 的本机 BeanWrapper 的数据绑定功能。这是使用统一 EL 进行视图到模型数据绑定的一种替代方法。有关更多信息,请参见该类的 Javadoc API。
默认情况下,WebFlow 在进入每个视图状态时都会进行客户端重定向。但是,如果在 Ajax 请求期间保持相同的视图状态(例如,没有“to”属性的转换),那么就不会有客户端重定向。这种行为对于 Spring Web Flow2 用户应该非常熟悉。它适用于支持浏览器后退按钮的顶级流,同时还可以利用 Ajax 和部分呈现,用于在表单验证、分页槽搜索结果等视图中保持不变的用例。但是,在转换到新的视图状态之后,总是会进行客户端重定向。这使得不可能在页面或模态对话框中嵌入流并执行多个视图状态,而不会导致整页刷新。因此,如果你的用例需要嵌入一个流,你可以在“嵌入”模式中启动它。
在上面的示例中,假设在`/user/login`、`/user/registration`、`/hotels/booking`和`/flights/booking`目录中有位于`WEB-INF`中的流 ID,则最终得到的流 ID 分别为`user/login`、`hotels/booking`和`flights/booking`。
@@ -354,29 +354,29 @@ public ViewFactoryCreator viewFactoryCreator() {
```
#### [](#builder-service-conversion)转换-服务
#### 转换-服务
使用`conversion-service`属性定制 Web 流系统使用的`ConversionService`。类型转换用于在流执行期间(例如在处理请求参数、调用操作等时)需要从一种类型转换为另一种类型。支持许多常见的对象类型,如数字、类和枚举。但是,你可能需要为自定义数据类型提供自己的类型转换和格式逻辑。有关如何提供自定义类型转换逻辑的重要信息,请阅读[第 5.7 节,“执行类型转换”](views.html#view-type-conversion)。
#### [](#builder-service-expression-parser)表达式分析器
#### 表达式分析器
使用`expression-parser`属性定制 Web 流系统使用的`ExpressionParser`。默认表达式分析器使用统一的 EL(如果在 Classpath 上可用),否则使用 Spring EL。
从版本 2.1 Spring 开始,Web 流使用 Spring 3 中引入的[类型转换](http://static.springsource.org/spring/docs/3.0.x/spring-framework-reference/html/validation.html#core-convert)和[formatting](http://static.springsource.org/spring/docs/3.0.x/spring-framework-reference/html/validation.html#format)系统来满足几乎所有的类型转换需求。以前,Web 流应用程序使用的类型转换机制与 Spring MVC 中的机制不同,后者依赖于`java.beans.PropertyEditor`抽象。 Spring 3 提供了一种替代 PropertYeditor 的现代类型转换方法,而 PropertYeditor 实际上受到了 Web Flow 自己的类型转换系统的影响。因此,Web 流用户应该会发现使用新的 Spring 3 类型转换是很自然的。这种变化的另一个明显且非常重要的好处是,现在可以跨 Spring MVC 和 Spring Web 流使用单一类型转换机制。
### [](#converter-upgrade-to-spring-3)5.7.2。升级到 Spring 3 类型转换和格式化
### 5.7.2.升级到 Spring 3 类型转换和格式化
这对现有的应用程序实际上意味着什么?现有的应用程序很可能通过 Spring 绑定中可用的`DefaultConversionService`的子类来注册它们自己的类型`org.springframework.binding.convert.converters.Converter`的转换器。这些转换器可以像以前一样继续注册。它们将被改编为 Spring 3`GenericConverter`类型,并以 Spring 3`org.springframework.core.convert.ConversionService`实例注册。换句话说,现有的转换器将通过 Spring 的类型转换服务被调用。
...
...
@@ -172,7 +172,7 @@ public class ApplicationConversionService extends DefaultConversionService {
总之, Spring 3 类型转换和格式现在几乎只在 Web 流中使用。尽管现有的应用程序将在没有任何更改的情况下工作,但我们鼓励朝着统一 Spring MVC 和 Spring 应用程序的 Web 流部分的类型转换需求的方向发展。
### [](#converter-configuration)5.7.3。配置类型转换和格式
### 5.7.3.配置类型转换和格式
在 Spring MVC 中,`FormattingConversionService`的实例是通过自定义 MVC 名称空间自动创建的:
...
...
@@ -265,7 +265,7 @@ public class ApplicationConversionServiceFactoryBean extends FormattingConversio
当然,混搭也是可以的。通过“ApplicationConversionService”注册新的 Spring 3<gtr="98"/>类型。通过“DefaultConversionService”注册现有的 Spring binding<gtr="99"/>类型。
### [](#converter-working-with)5.7.4。使用 Spring 3 类型转换和格式化
### 5.7.4.使用 Spring 3 类型转换和格式化
要理解的一个重要概念是类型转换器和格式化程序之间的区别。
...
...
@@ -279,17 +279,17 @@ Web 开发人员将发现`Formatter`接口最相关,因为它适合 Web 应用
新类型转换的最佳特性之一是能够使用注释以简洁的方式更好地控制格式。注释可以放在模型属性和映射到请求的 @Controller 方法的参数上。 Spring 开箱即用提供了两个注释`NumberFormat`和`DateTimeFormat`,但你可以创建自己的注释,并将它们与相关的格式设置逻辑一起注册。你可以在[Spring Travel](https://src.springframework.org/svn/spring-samples/travel)和[Petcare](https://src.springframework.org/svn/spring-samples/petcare)中看到`DateTimeFormat`注释的示例,以及[Spring Samples](https://src.springframework.org/svn/spring-samples)存储库中的其他示例。
### [](#converter-dates)5.7.6。与日期合作
### 5.7.6.与日期合作
`DateTimeFormat`注释意味着使用[Joda Time](http://joda-time.sourceforge.net/)。如果在 Classpath 上存在该注释,则自动启用该注释的使用。默认情况下, Spring MVC 或 Web 流都不会注册任何其他的日期格式化程序或转换器。因此,对于应用程序来说,注册一个自定义格式化程序来指定打印和解析日期的默认方式是很重要的。另一方面,`DateTimeFormat`注释在需要偏离默认值的地方提供了更细粒度的控制。
有关使用 Spring 3 类型转换和格式的更多信息,请参阅[Spring documentation](http://static.springsource.org/spring/docs/3.0.x/spring-framework-reference/html/index.html)的相关部分。
在模型对象中定义验证逻辑是验证其状态的最简单方法。一旦这种逻辑根据 Web 流约定进行了结构化,那么 Web 流将在视图状态回发生命周期期间自动调用该逻辑。Web 流约定让你通过视图状态来构造模型验证逻辑,从而使你能够轻松地验证在该视图上可编辑的模型属性的子集。要做到这一点,只需创建一个名为`validate${state}`的公共方法,其中`${state}`是你希望在其中运行验证的视图状态的 ID。例如:
第二种方法是定义一个单独的对象,称为*验证器*,它验证你的模型对象。要做到这一点,首先创建一个类,其名称具有模式 ${model}validator,其中`${model}`是模型表达式的头化形式,例如`booking`。然后定义一个名为`validate${state}`的公共方法,其中`${state}`是你的视图状态的 ID,例如`enterBookingDetails`。然后将类部署为 Spring Bean。可以定义任意数量的验证方法。例如:
...
...
@@ -482,7 +482,7 @@ public class BookingValidator {
必须使用命名约定`${model}Validator`将验证器注册为 Spring bean,才能自动检测和调用。在上面的示例中, Spring 2.5 Classpath-扫描将检测到`@Component`并自动将其注册为名称为`bookingValidator`的 Bean。然后,每当需要验证`booking`模型时,将为你调用这个`bookingValidator`实例。
Spring Web 流的`MessageContext`是用于在流执行过程中记录消息的 API。可以将纯文本消息添加到上下文中,以及由 Spring `MessageSource`解析的国际化消息。消息可以通过视图进行呈现,并在流执行重定向后自动保留。提供了三个不同的消息严重性:`info`、`warning`和`error`。此外,还存在一个方便的`MessageBuilder`用于流畅地构造消息。
国际化消息是在由 Spring `MessageSource`访问的消息包中定义的。要创建特定于流的消息包,只需在流的目录中定义`messages.properties`文件。为每个需要支持的额外`Locale`创建一个默认的`messages.properties`文件和一个.properties 文件。
...
...
@@ -658,7 +658,7 @@ reservationConfirmation=We have processed your reservation - thank you and enjoy
这个版本提供了一条到 Spring Framework5 的升级路径,而这条路径又需要 Java8+、 Servlet 3.1、 Hibernate 5、Tiles3。有关更多详细信息,请参见[Spring Framework wiki](https://github.com/spring-projects/spring-framework/wiki/What%27s-New-in-Spring-Framework-5.x)。[样品库](https://github.com/spring-projects/spring-webflow-samples)已升级到 Spring Web 流 2.5。
这个版本提供了一条到 Spring Framework5 的升级路径,而这条路径又需要 Java8+、 Servlet 3.1、 Hibernate 5、Tiles3.有关更多详细信息,请参见[Spring Framework wiki](https://github.com/spring-projects/spring-framework/wiki/What%27s-New-in-Spring-Framework-5.x)。[样品库](https://github.com/spring-projects/spring-webflow-samples)已升级到 Spring Web 流 2.5.
Spring Web Flow2.2 中引入的内部 Portlet 集成已经进行了升级,以实现 JSF2.0 的兼容性。Portlet 环境不支持一些更高级的 JSF2.0 特性,例如部分状态保存,但是,现有的应用程序现在可以升级到所需的最低 JSF 版本。升级后的项目将需要确保`<faces:resources>`元素被包括在其 Spring 配置中。
Spring Web Flow2.2 版本以 2.1 为基础,增加了对核心 JSF2 特性的支持,2.1 中不支持的以下特性现在可用:部分状态保存、JSF2 资源请求、处理和 JSF2Ajax 请求。在这一点上,对 JSF2 的支持被认为是全面的,尽管并不涵盖所有的 JSF2 特性--排除的主要是与 Web 流提供的核心价值重叠的特性,例如与导航和状态管理有关的特性。
有关重要的配置更改,请参见[第 13.3 节,“配置用于 JSF 的 Web 流”](spring-faces.html#spring-faces-webflow-config)。请注意,只支持 Sun Mojarra2.0.3 或更高版本的部分状态保存。它还没有得到 MyFaces 的支持。这是因为 MyFaces 在如何存储组件状态方面不那么容易定制。我们将与 MyFaces 合作提供这种支持。同时,你将需要在`web.xml`中使用`javax.faces.PARTIAL_STATE_SAVING`上下文参数来禁用 Apache MyFaces 的部分状态保存。
#### [](#d5e187)带原始表面组件的旅行样本
#### 带原始表面组件的旅行样本
演示 Spring Web 流和 JSF 支持的主要 Spring 旅行示例现在构建在 JSF2 和来自 PrimeFaces 组件库的组件上。请核对一下分配中的订货面样品。
...
...
@@ -131,34 +131,34 @@ svn co https://src.springframework.org/svn/spring-samples/webflow-primefaces-sho
```
### [](#whatsnew-sec)2.4.2。 Spring 安全 Facelets 标记库
### 2.4.2. Spring 安全 Facelets 标记库
Spring 新的安全标记库可用于 JSF2.0 或 JSF1.2Facelets 视图。它提供了一个 \<authorize\>标记以及几个 EL 函数。有关更多详细信息,请参见[Section 13.9, “Using the Spring Security Facelets Tag Library”](spring-faces.html#spring-faces-security-taglib)。
### [](#whatsnew-versions)2.4.3。 Spring JavaScript 更新
### 2.4.3. Spring JavaScript 更新
#### [](#d5e200)弃用资源 servlet
#### 弃用资源 servlet
从 Spring 3.0.4 开始, Spring 框架包括对 ResourcesServlet 的替换。请参阅 Spring 框架文档了解定制 MVC 名称空间的详细信息,特别是新的[“资源”](http://static.springsource.org/spring/docs/3.0.x/spring-framework-reference/html/mvc.html#mvc-static-resources)元素。
#### [](#d5e204)Dojo1.5 和 Dojox
#### Dojo1.5 和 Dojox
捆绑的定制 Dojo 版本升级到了 1.5 版本。它现在包括 Dojox。
请注意,通常鼓励应用程序准备自己的定制 Dojo 构建以优化性能,这取决于 Dojo 的哪些部分通常一起使用。有关示例,请参见 Spring Web 流用于准备自己的定制 Dojo 构建的[scripts](https://src.springframework.org/svn/spring-webflow/branches/spring-webflow-2.2-maintenance/spring-js-resources/scripts/dojo)。