diff --git a/spring-webflow/src/main/java/org/springframework/webflow/engine/impl/FlowExecutionImpl.java b/spring-webflow/src/main/java/org/springframework/webflow/engine/impl/FlowExecutionImpl.java index 0a87b8d4..6256ddc1 100644 --- a/spring-webflow/src/main/java/org/springframework/webflow/engine/impl/FlowExecutionImpl.java +++ b/spring-webflow/src/main/java/org/springframework/webflow/engine/impl/FlowExecutionImpl.java @@ -343,7 +343,13 @@ public class FlowExecutionImpl implements FlowExecution, Externalizable { listeners.fireStateEntering(context, newState); FlowSessionImpl session = getActiveSessionInternal(); State previousState = (State) session.getState(); + if (previousState != null && previousState.isViewState()) { + session.destroyViewScope(); + } session.setState(newState); + if (newState.isViewState()) { + session.initViewScope(); + } listeners.fireStateEntered(context, previousState); } diff --git a/spring-webflow/src/main/java/org/springframework/webflow/engine/impl/FlowSessionImpl.java b/spring-webflow/src/main/java/org/springframework/webflow/engine/impl/FlowSessionImpl.java index d69357ed..871186b9 100644 --- a/spring-webflow/src/main/java/org/springframework/webflow/engine/impl/FlowSessionImpl.java +++ b/spring-webflow/src/main/java/org/springframework/webflow/engine/impl/FlowSessionImpl.java @@ -126,12 +126,6 @@ class FlowSessionImpl implements FlowSession, Externalizable { return parent == null; } - // package-private - - Flow getFlow() { - return flow; - } - // custom serialization public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException { @@ -148,6 +142,12 @@ class FlowSessionImpl implements FlowSession, Externalizable { out.writeObject(parent); } + // package-private + + Flow getFlow() { + return flow; + } + // package private setters for setting/updating internal state // used by FlowExecutionImplStateRestorer @@ -172,14 +172,8 @@ class FlowSessionImpl implements FlowSession, Externalizable { Assert.notNull(state, "The state is required"); Assert.isTrue(flow == state.getOwner(), "The state does not belong to the flow associated with this flow session"); - if (this.state != null && this.state.isViewState()) { - destroyViewScope(); - } this.state = state; this.stateId = state.getId(); - if (this.state.isViewState()) { - initViewScope(); - } } /** @@ -196,13 +190,17 @@ class FlowSessionImpl implements FlowSession, Externalizable { return stateId; } - // internal helpers - - private void initViewScope() { + /** + * Initialize the view scope data structure. + */ + void initViewScope() { scope.put(FLOW_VIEW_MAP_ATTRIBUTE, new LocalAttributeMap()); } - private void destroyViewScope() { + /** + * Destroy the view scope data structure. + */ + void destroyViewScope() { scope.remove(FLOW_VIEW_MAP_ATTRIBUTE); } diff --git a/spring-webflow/src/test/java/org/springframework/webflow/engine/ViewStateTests.java b/spring-webflow/src/test/java/org/springframework/webflow/engine/ViewStateTests.java index d4ab66e0..996b2d9c 100644 --- a/spring-webflow/src/test/java/org/springframework/webflow/engine/ViewStateTests.java +++ b/spring-webflow/src/test/java/org/springframework/webflow/engine/ViewStateTests.java @@ -208,7 +208,7 @@ public class ViewStateTests extends TestCase { state.resume(context); assertTrue(context.getFlowExecutionContext().isActive()); assertEquals("next", context.getCurrentState().getId()); - assertFalse(context.getFlowScope().contains("foo")); + assertFalse(context.getViewScope().contains("foo")); } protected TransitionCriteria on(String event) {