Spring Web Flow - Flow and view scope
Most web apps are content to use the Servlet defined scopes of request, session, and context. However, much of the stateful data used in a web app doesn't quite fit into any of these scopes. Typically, such data lasts longer than a single request, but shorter than a session. Session scope is usually used in this case. This forces the developer to essentially perform manual memory management to place things into session scope, and then explicitly remove them when they are no longer needed for that portion of the application. This can be troublesome, as there are usually multiple places where attributes must be removed, as there are often several actions that the user can invoke to take them out of the use case where the attributes are needed.
In large or growing applications, attribute cleanup code becomes a necessary and pervasive clutter throughout the code. Forgetting to clean up attributes, or cleaning up the wrong ones by mistake, can introduce bugs.
SWF solves this by providing some additional scopes which better fit the life cycle of application attributes.
SWF introduces the concepts of flows, which are reusable modular groupings of behavior represented as a state machine consisting of states and transitions between them. A flow may include action-states for invoking server-side behavior, view-states for rendering pages to the user, and others. Flows often represent use cases. Flow-scoped attributes persist for the duration of the flow, and are cleaned up automatically when the flow ends. This results in attributes which only persist for the duration of the use case where they are needed.
ViewStates within a flow render a view to the user. Transitions from a viewState may navigate to a different state or can remain in the same viewState, rerendering the view (with or without AJAX) after performing some actions. Attributes in viewScope persist while control remains in the viewState. ViewScoped attributes survive browser refreshes, and are useful for data that is relevant only for the view being rendered, such as data which is used in AJAX requests, or for flags which influence the markup in some way. When a transition is invoked which leaves the viewState, viewScoped attributes are cleaned up.
In summary, SWF's additional scopes better fit the lifecycle of application attributes, and using these additional scopes removes the need to manually manage your attributes, resulting in less attribute-juggling plumbing code throughout your app and less potential for bugs.