Remove dependency on internal MyFaces class
Issue: SWF-1712
This commit is contained in:
@@ -22,8 +22,6 @@ import javax.faces.application.StateManager.SerializedView;
|
||||
import javax.faces.context.FacesContext;
|
||||
import javax.faces.render.ResponseStateManager;
|
||||
|
||||
import org.apache.myfaces.renderkit.MyfacesResponseStateManager;
|
||||
import org.apache.myfaces.application.viewstate.StateCacheUtils;
|
||||
import org.springframework.webflow.execution.RequestContext;
|
||||
import org.springframework.webflow.execution.RequestContextHolder;
|
||||
|
||||
@@ -37,7 +35,8 @@ import org.springframework.webflow.execution.RequestContextHolder;
|
||||
* containing the real state to save.
|
||||
*
|
||||
* <p>Since JSF 2.0, the strategy used by MyFaces to determine if a
|
||||
* {@link MyfacesResponseStateManager} is available will always succeed since it
|
||||
* {@link org.apache.myfaces.renderkit.MyfacesResponseStateManager} is available
|
||||
* will always succeed since it
|
||||
* follows {@link FacesWrapper}s to find the root <tt>HtmlResponseStateManager</tt>
|
||||
* implementation. Since state management for web flow requests is handled by the
|
||||
* {@link FlowResponseStateManager} this* assumption causes problems and results
|
||||
@@ -51,7 +50,7 @@ import org.springframework.webflow.execution.RequestContextHolder;
|
||||
* @see FlowRenderKit
|
||||
*/
|
||||
@SuppressWarnings("deprecation")
|
||||
public class MyFacesFlowResponseStateManager extends MyfacesResponseStateManager
|
||||
public class MyFacesFlowResponseStateManager extends ResponseStateManager
|
||||
implements FacesWrapper<ResponseStateManager> {
|
||||
|
||||
private final ResponseStateManager wrapped;
|
||||
@@ -64,31 +63,11 @@ public class MyFacesFlowResponseStateManager extends MyfacesResponseStateManager
|
||||
return this.wrapped;
|
||||
}
|
||||
|
||||
private MyfacesResponseStateManager getWrappedMyfacesResponseStateManager() {
|
||||
return StateCacheUtils.getMyFacesResponseStateManager(this.wrapped);
|
||||
}
|
||||
|
||||
public boolean isWriteStateAfterRenderViewRequired(FacesContext facesContext) {
|
||||
MyfacesResponseStateManager wrapped = getWrappedMyfacesResponseStateManager();
|
||||
if (wrapped != null) {
|
||||
return wrapped.isWriteStateAfterRenderViewRequired(facesContext);
|
||||
}
|
||||
return super.isWriteStateAfterRenderViewRequired(facesContext);
|
||||
}
|
||||
|
||||
public void saveState(FacesContext facesContext, Object state) {
|
||||
RequestContext requestContext = RequestContextHolder.getRequestContext();
|
||||
requestContext.getViewScope().put(FlowResponseStateManager.FACES_VIEW_STATE, state);
|
||||
}
|
||||
|
||||
public void writeStateAsUrlParams(FacesContext facesContext, SerializedView serializedview) {
|
||||
MyfacesResponseStateManager wrapped = getWrappedMyfacesResponseStateManager();
|
||||
if (wrapped != null) {
|
||||
wrapped.writeStateAsUrlParams(facesContext, serializedview);
|
||||
}
|
||||
super.writeStateAsUrlParams(facesContext, serializedview);
|
||||
}
|
||||
|
||||
public Object getComponentStateToRestore(FacesContext context) {
|
||||
return getWrapped().getComponentStateToRestore(context);
|
||||
}
|
||||
|
||||
@@ -1,92 +0,0 @@
|
||||
package org.springframework.faces.webflow;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.StringWriter;
|
||||
|
||||
import javax.faces.context.FacesContext;
|
||||
|
||||
import org.apache.myfaces.renderkit.MyfacesResponseStateManager;
|
||||
import org.apache.myfaces.test.base.AbstractJsfTestCase;
|
||||
import org.apache.myfaces.test.mock.MockResponseWriter;
|
||||
import org.easymock.EasyMock;
|
||||
import org.springframework.webflow.engine.ViewState;
|
||||
import org.springframework.webflow.execution.RequestContextHolder;
|
||||
import org.springframework.webflow.execution.ViewFactory;
|
||||
import org.springframework.webflow.test.MockFlowExecutionContext;
|
||||
import org.springframework.webflow.test.MockFlowExecutionKey;
|
||||
import org.springframework.webflow.test.MockFlowSession;
|
||||
import org.springframework.webflow.test.MockRequestContext;
|
||||
|
||||
/**
|
||||
* Tests for {@link MyFacesFlowResponseStateManager}.
|
||||
*
|
||||
* @author Phillip Webb
|
||||
*/
|
||||
public class MyFacesFlowResponseStateManagerTests extends AbstractJsfTestCase {
|
||||
|
||||
private MockMyfacesResponseStateManager root;
|
||||
private FlowResponseStateManager flow;
|
||||
private MyFacesFlowResponseStateManager manager;
|
||||
private MockRequestContext requestContext;
|
||||
|
||||
public MyFacesFlowResponseStateManagerTests(String name) {
|
||||
super(name);
|
||||
}
|
||||
|
||||
protected void setUp() throws Exception {
|
||||
super.setUp();
|
||||
this.root = new MockMyfacesResponseStateManager();
|
||||
this.flow = new FlowResponseStateManager(this.root);
|
||||
this.manager = new MyFacesFlowResponseStateManager(this.flow);
|
||||
this.requestContext = new MockRequestContext();
|
||||
MockFlowExecutionContext executionContext = requestContext.getMockFlowExecutionContext();
|
||||
MockFlowSession session = executionContext.getMockActiveSession();
|
||||
ViewFactory viewFactory = EasyMock.createNiceMock(ViewFactory.class);
|
||||
session.setState(new ViewState(session.getDefinitionInternal(), "view", viewFactory));
|
||||
executionContext.setKey(new MockFlowExecutionKey("x"));
|
||||
RequestContextHolder.setRequestContext(requestContext);
|
||||
}
|
||||
|
||||
protected void tearDown() throws Exception {
|
||||
RequestContextHolder.setRequestContext(null);
|
||||
super.tearDown();
|
||||
}
|
||||
|
||||
public void testDelegatesIsWriteStateAfterRenderViewRequired() throws Exception {
|
||||
this.manager.isWriteStateAfterRenderViewRequired(this.facesContext);
|
||||
assertTrue(this.root.isWriteStateAfterRenderViewRequiredCalled);
|
||||
}
|
||||
|
||||
public void testDelegatesWriteState() throws Exception {
|
||||
RequestContextHolder.setRequestContext(null);
|
||||
this.facesContext.setResponseWriter(new MockResponseWriter(new StringWriter()));
|
||||
this.manager.writeState(this.facesContext, new Object());
|
||||
assertTrue(this.root.writeStateCalled);
|
||||
}
|
||||
|
||||
public void testTriggersSaveStateInFlowResponseStateManager() throws Exception {
|
||||
Object state = new Object();
|
||||
this.manager.saveState(this.facesContext, state);
|
||||
assertSame(state, requestContext.getViewScope().get(FlowResponseStateManager.FACES_VIEW_STATE));
|
||||
assertFalse(this.root.saveStateCalled);
|
||||
}
|
||||
|
||||
private static class MockMyfacesResponseStateManager extends MyfacesResponseStateManager {
|
||||
private boolean isWriteStateAfterRenderViewRequiredCalled;
|
||||
private boolean saveStateCalled;
|
||||
private boolean writeStateCalled;
|
||||
|
||||
public boolean isWriteStateAfterRenderViewRequired(FacesContext facesContext) {
|
||||
this.isWriteStateAfterRenderViewRequiredCalled = true;
|
||||
return true;
|
||||
}
|
||||
|
||||
public void saveState(FacesContext facesContext, Object state) {
|
||||
this.saveStateCalled = true;
|
||||
}
|
||||
|
||||
public void writeState(FacesContext context, Object state) throws IOException {
|
||||
this.writeStateCalled = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user