Prevent NPE in Mojarra when creating initial view
Refactor JsfViewFactory to only attempt a restoreView when state is available. This prevents a NullPointerException from being thrown when using Mojarra with partial state saving disabled. This change also makes Web Flow behave in a similar way to the standard FacesServlet. Issue: SWF-1571
This commit is contained in:
@@ -72,12 +72,15 @@ public class JsfViewFactoryTests extends TestCase {
|
||||
|
||||
private final MockHttpServletResponse response = new MockHttpServletResponse();
|
||||
|
||||
private LocalAttributeMap<Object> viewScope = new LocalAttributeMap<Object>();
|
||||
|
||||
protected void setUp() throws Exception {
|
||||
configureJsf();
|
||||
this.extContext.setNativeContext(this.servletContext);
|
||||
this.extContext.setNativeRequest(this.request);
|
||||
this.extContext.setNativeResponse(this.response);
|
||||
RequestContextHolder.setRequestContext(this.context);
|
||||
EasyMock.expect(this.context.getViewScope()).andStubReturn(this.viewScope);
|
||||
EasyMock.expect(this.context.getFlashScope()).andStubReturn(this.flashMap);
|
||||
EasyMock.expect(this.context.getExternalContext()).andStubReturn(this.extContext);
|
||||
EasyMock.expect(this.context.getRequestParameters()).andStubReturn(
|
||||
@@ -148,6 +151,7 @@ public class JsfViewFactoryTests extends TestCase {
|
||||
EasyMock.expectLastCall().andReturn(true);
|
||||
|
||||
EasyMock.replay(new Object[] { this.context });
|
||||
setupViewState();
|
||||
|
||||
View restoredView = this.factory.getView(this.context);
|
||||
|
||||
@@ -194,6 +198,7 @@ public class JsfViewFactoryTests extends TestCase {
|
||||
EasyMock.expectLastCall().andReturn(true);
|
||||
|
||||
EasyMock.replay(new Object[] { this.context });
|
||||
setupViewState();
|
||||
|
||||
View restoredView = this.factory.getView(this.context);
|
||||
|
||||
@@ -229,6 +234,7 @@ public class JsfViewFactoryTests extends TestCase {
|
||||
EasyMock.expectLastCall().andReturn(true);
|
||||
|
||||
EasyMock.replay(new Object[] { this.context });
|
||||
setupViewState();
|
||||
|
||||
View restoredView = this.factory.getView(this.context);
|
||||
|
||||
@@ -279,6 +285,7 @@ public class JsfViewFactoryTests extends TestCase {
|
||||
|
||||
this.context.inViewState();
|
||||
EasyMock.expectLastCall().andReturn(true);
|
||||
setupViewState();
|
||||
|
||||
EasyMock.replay(new Object[] { this.context });
|
||||
this.factory.getView(this.context);
|
||||
@@ -289,6 +296,10 @@ public class JsfViewFactoryTests extends TestCase {
|
||||
.getExceptionQueuedEventContext().getException());
|
||||
}
|
||||
|
||||
private void setupViewState() {
|
||||
this.viewScope.put(FlowResponseStateManager.FACES_VIEW_STATE, "X");
|
||||
}
|
||||
|
||||
private class NoExecutionLifecycle extends FlowLifecycle {
|
||||
|
||||
public NoExecutionLifecycle(Lifecycle delegate) {
|
||||
|
||||
Reference in New Issue
Block a user