Author: nbelaevski
Date: 2008-08-04 19:15:16 -0400 (Mon, 04 Aug 2008)
New Revision: 9904
Modified:
trunk/framework/impl/src/main/java/org/ajax4jsf/application/AjaxStateManager.java
trunk/framework/impl/src/main/java/org/ajax4jsf/context/ContextInitParameters.java
Log:
https://jira.jboss.org/jira/browse/RF-3671
Modified:
trunk/framework/impl/src/main/java/org/ajax4jsf/application/AjaxStateManager.java
===================================================================
---
trunk/framework/impl/src/main/java/org/ajax4jsf/application/AjaxStateManager.java 2008-08-04
22:30:44 UTC (rev 9903)
+++
trunk/framework/impl/src/main/java/org/ajax4jsf/application/AjaxStateManager.java 2008-08-04
23:15:16 UTC (rev 9904)
@@ -21,10 +21,13 @@
package org.ajax4jsf.application;
+import java.io.ByteArrayInputStream;
+import java.io.ByteArrayOutputStream;
import java.io.IOException;
+import java.io.ObjectInputStream;
+import java.io.ObjectOutputStream;
import java.io.StringWriter;
import java.lang.reflect.Constructor;
-import java.lang.reflect.Method;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
@@ -35,7 +38,6 @@
import javax.faces.FacesException;
import javax.faces.FactoryFinder;
import javax.faces.application.StateManager;
-import javax.faces.application.StateManager.SerializedView;
import javax.faces.component.UIComponentBase;
import javax.faces.component.UIViewRoot;
import javax.faces.context.ExternalContext;
@@ -46,6 +48,7 @@
import javax.faces.render.ResponseStateManager;
import org.ajax4jsf.context.AjaxContext;
+import org.ajax4jsf.context.ContextInitParameters;
import org.ajax4jsf.model.KeepAlive;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
@@ -296,6 +299,49 @@
return matcher.group(1);
}
+ private static final Object handleRestoreState(FacesContext context, Object state) {
+ if (ContextInitParameters.isSerializeServerState(context)) {
+ ObjectInputStream ois = null;
+ try {
+ ois = new ObjectInputStream(new ByteArrayInputStream((byte[]) state));
+ return ois.readObject();
+ } catch (Exception e) {
+ throw new FacesException(e);
+ } finally {
+ if (ois != null) {
+ try {
+ ois.close();
+ } catch (IOException ignored) { }
+ }
+ }
+ } else {
+ return state;
+ }
+ }
+
+ private static final Object handleSaveState(FacesContext context, Object state) {
+ if (ContextInitParameters.isSerializeServerState(context)) {
+ ByteArrayOutputStream baos = new ByteArrayOutputStream(1024);
+ ObjectOutputStream oas = null;
+ try {
+ oas = new ObjectOutputStream(baos);
+ oas.writeObject(state);
+ oas.flush();
+ } catch (Exception e) {
+ throw new FacesException(e);
+ } finally {
+ if (oas != null) {
+ try {
+ oas.close();
+ } catch (IOException ignored) { }
+ }
+ }
+ return baos.toByteArray();
+ } else {
+ return state;
+ }
+ }
+
/*
* (non-Javadoc)
*
@@ -345,7 +391,7 @@
}
if (null != serializedView) {
treeStructure = (TreeStructureNode) serializedView[0];
- state = (Object[]) serializedView[1];
+ state = (Object[]) handleRestoreState(context, serializedView[1]);
}
if (null != treeStructure) {
viewRoot = (UIViewRoot) treeStructure.restore(componentLoader);
@@ -401,7 +447,7 @@
viewStateArray = new Object[]{treeStructure, state};
} else {
viewStateArray = saveStateInSession(context, treeStructure,
- state);
+ handleSaveState(context, state));
}
}
Modified:
trunk/framework/impl/src/main/java/org/ajax4jsf/context/ContextInitParameters.java
===================================================================
---
trunk/framework/impl/src/main/java/org/ajax4jsf/context/ContextInitParameters.java 2008-08-04
22:30:44 UTC (rev 9903)
+++
trunk/framework/impl/src/main/java/org/ajax4jsf/context/ContextInitParameters.java 2008-08-04
23:15:16 UTC (rev 9904)
@@ -27,6 +27,14 @@
// parameters. Do not Instantiate !
}
+ public static final String[] SERIALIZE_SERVER_STATE = new String[] {
+ "org.ajax4jsf.SERIALIZE_SERVER_STATE",
+
+ /* detect MyFaces vs. RI */
+ "com.sun.faces.serializeServerState",
+ "org.apache.myfaces.SERIALIZE_STATE_IN_SESSION"
+ };
+
public static final String[] NUMBER_OF_VIEWS_IN_SESSION =
{"com.sun.faces.numberOfViewsInSession"};
public static final String[] NUMBER_OF_LOGICAL_VIEWS_IN_SESSION =
{"com.sun.faces.numberOfLogicalViews"};
@@ -37,6 +45,10 @@
public static final String
HANDLE_VIEW_EXPIRED_ON_CLIENT="org.ajax4jsf.handleViewExpiredOnClient";
+ public static final boolean isSerializeServerState(FacesContext context) {
+ return getBoolean(context, SERIALIZE_SERVER_STATE, false);
+ }
+
/**
* Get number of views for store in session by {@link AjaxStateManager}
* @param context - current faces context.