Fixing JSF state-saving mechanism and adding helpful debug logging
This commit is contained in:
@@ -16,6 +16,10 @@
|
||||
<el-resolver>org.springframework.webflow.core.expression.el.ScopeSearchingELResolver</el-resolver>
|
||||
<view-handler>org.springframework.faces.webflow.FlowExecutionViewHandler</view-handler>
|
||||
</application>
|
||||
|
||||
<lifecycle>
|
||||
<phase-listener>org.springframework.faces.support.RequestLoggingPhaseListener</phase-listener>
|
||||
</lifecycle>
|
||||
|
||||
<component>
|
||||
<component-type>spring.faces.ClientTextValidator</component-type>
|
||||
|
||||
@@ -0,0 +1,26 @@
|
||||
package org.springframework.faces.support;
|
||||
|
||||
import javax.faces.event.PhaseEvent;
|
||||
import javax.faces.event.PhaseId;
|
||||
import javax.faces.event.PhaseListener;
|
||||
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
|
||||
public class RequestLoggingPhaseListener implements PhaseListener {
|
||||
|
||||
private Log logger = LogFactory.getLog(RequestLoggingPhaseListener.class);
|
||||
|
||||
public void afterPhase(PhaseEvent event) {
|
||||
// no-op
|
||||
}
|
||||
|
||||
public void beforePhase(PhaseEvent event) {
|
||||
logger.debug("Entering JSF Phase: " + event.getPhaseId());
|
||||
}
|
||||
|
||||
public PhaseId getPhaseId() {
|
||||
return PhaseId.ANY_PHASE;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -25,6 +25,7 @@ public class FlowActionListener implements ActionListener {
|
||||
} else {
|
||||
context.getExternalContext().getRequestMap().remove(JsfView.EVENT_KEY);
|
||||
}
|
||||
context.renderResponse();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -13,9 +13,11 @@ import org.springframework.webflow.execution.RequestContextHolder;
|
||||
|
||||
public class FlowResponseStateManager extends ResponseStateManager {
|
||||
|
||||
private static final int TREE_STATE_INDEX = 0;
|
||||
private static final int VIEW_ID_INDEX = 0;
|
||||
|
||||
private static final int COMPONENT_STATE_INDEX = 1;
|
||||
private static final int TREE_STATE_INDEX = 1;
|
||||
|
||||
private static final int COMPONENT_STATE_INDEX = 2;
|
||||
|
||||
// TODO - This needs to be replaced with a common static, probably from FlowExecutorArgumentExtractor
|
||||
private static final String VIEW_STATE_PARAM = "org.springframework.webflow.FlowExecutionKey";
|
||||
@@ -25,21 +27,32 @@ public class FlowResponseStateManager extends ResponseStateManager {
|
||||
|
||||
private static final char[] STATE_FIELD_END = "\" />".toCharArray();
|
||||
|
||||
public Object getComponentStateToRestore(FacesContext context) {
|
||||
public Object getState(FacesContext context, String viewId) {
|
||||
Object[] structureAndState = new Object[2];
|
||||
structureAndState[0] = getTreeStructureToRestore(context, viewId);
|
||||
if (structureAndState[0] == null) {
|
||||
return null;
|
||||
}
|
||||
structureAndState[1] = getComponentStateToRestore(context);
|
||||
return structureAndState;
|
||||
}
|
||||
|
||||
Object[] state = (Object[]) RequestContextHolder.getRequestContext().getFlashScope().get(JsfView.STATE_KEY);
|
||||
return state[COMPONENT_STATE_INDEX];
|
||||
public Object getComponentStateToRestore(FacesContext context) {
|
||||
Object[] state = (Object[]) RequestContextHolder.getRequestContext().getFlowScope().get(JsfView.STATE_KEY);
|
||||
if (state == null) {
|
||||
return null;
|
||||
} else {
|
||||
return state[COMPONENT_STATE_INDEX];
|
||||
}
|
||||
}
|
||||
|
||||
public Object getTreeStructureToRestore(FacesContext context, String viewId) {
|
||||
Object[] state = (Object[]) RequestContextHolder.getRequestContext().getFlashScope().get(JsfView.STATE_KEY);
|
||||
return state[TREE_STATE_INDEX];
|
||||
}
|
||||
|
||||
public boolean isPostback(FacesContext context) {
|
||||
|
||||
// TODO Auto-generated method stub
|
||||
throw new UnsupportedOperationException("Auto-generated method stub");
|
||||
Object[] state = (Object[]) RequestContextHolder.getRequestContext().getFlowScope().get(JsfView.STATE_KEY);
|
||||
if (state == null || !state[VIEW_ID_INDEX].equals(viewId)) {
|
||||
return null;
|
||||
} else {
|
||||
return state[TREE_STATE_INDEX];
|
||||
}
|
||||
}
|
||||
|
||||
private FlowExecution getFlowExecution() {
|
||||
@@ -54,9 +67,10 @@ public class FlowResponseStateManager extends ResponseStateManager {
|
||||
*/
|
||||
public void writeState(FacesContext context, SerializedView state) throws IOException {
|
||||
|
||||
Object[] serializableState = new Object[] { state.getStructure(), state.getState() };
|
||||
Object[] serializableState = new Object[] { context.getViewRoot().getViewId(), state.getStructure(),
|
||||
state.getState() };
|
||||
|
||||
RequestContextHolder.getRequestContext().getFlashScope().put(JsfView.STATE_KEY, serializableState);
|
||||
RequestContextHolder.getRequestContext().getFlowScope().put(JsfView.STATE_KEY, serializableState);
|
||||
|
||||
Writer writer = context.getResponseWriter();
|
||||
writer.write(STATE_FIELD_START);
|
||||
|
||||
@@ -13,7 +13,7 @@ import org.springframework.webflow.execution.ViewFactory;
|
||||
|
||||
/**
|
||||
* A ViewFactoryCreator implementation for creating JSF ViewFactories
|
||||
* @author Jeremy Grellex
|
||||
* @author Jeremy Grelle
|
||||
*
|
||||
*/
|
||||
public class JsfViewFactoryCreator implements ViewFactoryCreator {
|
||||
|
||||
Reference in New Issue
Block a user