Proper handling of AjaxViewRoot in JsfView.saveState

This commit is contained in:
Jeremy Grelle
2009-04-17 20:14:09 +00:00
parent da9bb142e9
commit c7768ed617
3 changed files with 19 additions and 3 deletions

View File

@@ -46,7 +46,7 @@ public abstract class DelegatingViewRoot extends UIViewRoot {
this.original = original;
}
protected UIViewRoot getOriginalViewRoot() {
public UIViewRoot getOriginalViewRoot() {
return original;
}

View File

@@ -24,6 +24,7 @@ import javax.faces.lifecycle.Lifecycle;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.faces.ui.AjaxViewRoot;
import org.springframework.webflow.execution.Event;
import org.springframework.webflow.execution.RequestContext;
import org.springframework.webflow.execution.View;
@@ -120,7 +121,11 @@ public class JsfView implements View {
*/
public void saveState() {
FacesContext facesContext = FlowFacesContext.newInstance(requestContext, facesLifecycle);
facesContext.setViewRoot(viewRoot);
if (viewRoot instanceof AjaxViewRoot) {
facesContext.setViewRoot(((AjaxViewRoot) viewRoot).getOriginalViewRoot());
} else {
facesContext.setViewRoot(viewRoot);
}
try {
facesContext.getApplication().getStateManager().saveView(facesContext);
} finally {

View File

@@ -65,7 +65,7 @@ public class JsfViewTests extends TestCase {
jsfMock.setUp();
jsfMock.facesContext().getApplication().setViewHandler(new MockViewHandler());
jsfMock.application().setStateManager(new TestStateManager());
jsfMock.facesContext().getApplication().setStateManager(new TestStateManager());
jsfMock.facesContext().setResponseWriter(new MockResponseWriter(output, null, null));
UIViewRoot viewToRender = new UIViewRoot();
@@ -96,6 +96,17 @@ public class JsfViewTests extends TestCase {
jsfMock.tearDown();
}
public final void testSaveState() {
EasyMock.replay(new Object[] { context, flowExecutionContext, flowMap, flashScope });
view.saveState();
}
public final void testSaveState_AjaxViewRoot() {
EasyMock.replay(new Object[] { context, flowExecutionContext, flowMap, flashScope });
view.setViewRoot(new AjaxViewRoot(view.getViewRoot()));
view.saveState();
}
public final void testRender() throws IOException {
EasyMock.expect(flashScope.put(EasyMock.matches(FlowFacesContext.RENDER_RESPONSE_KEY), EasyMock.anyObject()))