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:
@@ -142,4 +142,13 @@ public class FlowResponseStateManager extends ResponseStateManagerWrapper {
|
||||
writer.endElement("input");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Determine if the request context has existing state.
|
||||
* @param context the request context
|
||||
* @return {@code true} if the context has state
|
||||
*/
|
||||
static boolean hasState(RequestContext context) {
|
||||
return (context != null) && (context.getViewScope().contains(FACES_VIEW_STATE));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -132,7 +132,12 @@ public class JsfViewFactory implements ViewFactory {
|
||||
|
||||
private UIViewRoot getViewStateViewRoot(RequestContext context, FacesContext facesContext, ViewHandler viewHandler,
|
||||
String viewName) {
|
||||
UIViewRoot viewRoot = viewHandler.restoreView(facesContext, viewName);
|
||||
UIViewRoot viewRoot = null;
|
||||
if (FlowResponseStateManager.hasState(context)) {
|
||||
// Only try an initial restore if we have state (see SWF-1571)
|
||||
viewRoot = viewHandler.restoreView(facesContext, viewName);
|
||||
}
|
||||
|
||||
if (viewRoot != null) {
|
||||
if (logger.isDebugEnabled()) {
|
||||
logger.debug("UIViewRoot restored for '" + viewName + "'");
|
||||
@@ -144,6 +149,7 @@ public class JsfViewFactory implements ViewFactory {
|
||||
}
|
||||
viewRoot = viewHandler.createView(facesContext, viewName);
|
||||
}
|
||||
|
||||
return viewRoot;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user