From 78650d616797ca79e74498a92ebef9fab32061ab Mon Sep 17 00:00:00 2001 From: Jeremy Grelle Date: Mon, 17 Mar 2008 14:51:19 +0000 Subject: [PATCH] SWF-537 - FlowViewStateManager set repeatedly on application instance after application initialization. --- .../src/main/java/META-INF/faces-config.xml | 4 +++ .../faces/webflow/FlowApplicationFactory.java | 31 +++++++++++++++++++ .../faces/webflow/FlowFacesContext.java | 8 +---- 3 files changed, 36 insertions(+), 7 deletions(-) create mode 100644 spring-faces/src/main/java/org/springframework/faces/webflow/FlowApplicationFactory.java diff --git a/spring-faces/src/main/java/META-INF/faces-config.xml b/spring-faces/src/main/java/META-INF/faces-config.xml index 1f0c9515..2a9ed428 100644 --- a/spring-faces/src/main/java/META-INF/faces-config.xml +++ b/spring-faces/src/main/java/META-INF/faces-config.xml @@ -14,6 +14,10 @@ org.springframework.faces.webflow.FlowViewHandler + + org.springframework.faces.webflow.FlowApplicationFactory + + org.springframework.faces.support.RequestLoggingPhaseListener diff --git a/spring-faces/src/main/java/org/springframework/faces/webflow/FlowApplicationFactory.java b/spring-faces/src/main/java/org/springframework/faces/webflow/FlowApplicationFactory.java new file mode 100644 index 00000000..2cf17c50 --- /dev/null +++ b/spring-faces/src/main/java/org/springframework/faces/webflow/FlowApplicationFactory.java @@ -0,0 +1,31 @@ +package org.springframework.faces.webflow; + +import javax.faces.application.Application; +import javax.faces.application.ApplicationFactory; + +public class FlowApplicationFactory extends ApplicationFactory { + + private ApplicationFactory delegate; + + private boolean stateManagerConfigured = false; + + public FlowApplicationFactory(ApplicationFactory delegate) { + this.delegate = delegate; + } + + public Application getApplication() { + Application app = delegate.getApplication(); + // Ensure that FlowViewStateManager is first in the chain + if (!stateManagerConfigured && app.getStateManager() != null) { + FlowViewStateManager sm = new FlowViewStateManager(app.getStateManager()); + app.setStateManager(sm); + stateManagerConfigured = true; + } + return app; + } + + public void setApplication(Application application) { + delegate.setApplication(application); + } + +} diff --git a/spring-faces/src/main/java/org/springframework/faces/webflow/FlowFacesContext.java b/spring-faces/src/main/java/org/springframework/faces/webflow/FlowFacesContext.java index 1f53967f..066ed476 100644 --- a/spring-faces/src/main/java/org/springframework/faces/webflow/FlowFacesContext.java +++ b/spring-faces/src/main/java/org/springframework/faces/webflow/FlowFacesContext.java @@ -73,13 +73,7 @@ public class FlowFacesContext extends FacesContext { FacesContext defaultFacesContext = facesContextFactory.getFacesContext(context.getExternalContext() .getNativeContext(), context.getExternalContext().getNativeRequest(), context.getExternalContext() .getNativeResponse(), lifecycle); - FlowFacesContext instance = new FlowFacesContext(context, defaultFacesContext); - - // Ensure that FlowViewStateManager is first in the chain - FlowViewStateManager sm = new FlowViewStateManager(instance.getApplication().getStateManager()); - instance.getApplication().setStateManager(sm); - - return instance; + return new FlowFacesContext(context, defaultFacesContext); } public FlowFacesContext(RequestContext context, FacesContext delegate) {