Various Changes - see below.
SECTION: Modified Files
----------------------------
M src/com/sun/faces/application/StateManagerImpl.java
M src/com/sun/faces/renderkit/ResponseStateManagerImpl.java
- EXPERIMENTAL
- Update state management to walk the tree once instead
of twice.
- Update the TreeNode/FacetNode structures to store
the state of the provided component if it isn't
transient.
- When reconstructing the view, state is restored
on each reconstructed component, again, preventing
an additional walk through the tree
- Updated the ResponseStateManager implementation to
ignore the provided state when writing/reading so
only the combined structure/state is written.
M src/com/sun/faces/config/WebConfiguration.java
- clean up the WebConfiguration API to make it a
little easier to use
- Added com.sun.faces.sendPoweredByHeader (enabled by
default). This will cause the default implementation
to add the X-Powered-By header (described in SRV.5.2)
to the response with a value of JSF/1.2
M src/com/sun/faces/context/ExternalContextImpl.java
- Add the X-Powered-By header during construction of
ExternaContextImpl
M src/com/sun/faces/lifecycle/LifecycleImpl.java
- removed uncessary casts
SECTION: Diffs
----------------------------
Index: src/com/sun/faces/application/StateManagerImpl.java
===================================================================
RCS file: /cvs/javaserverfaces-sources/jsf-ri/src/com/sun/faces/application/StateManagerImpl.java,v
retrieving revision 1.55
diff -u -r1.55 StateManagerImpl.java
--- src/com/sun/faces/application/StateManagerImpl.java 1 Sep 2006 01:22:34 -0000 1.55
+++ src/com/sun/faces/application/StateManagerImpl.java 6 Sep 2006 17:40:28 -0000
@@ -38,6 +38,7 @@
import java.io.IOException;
import java.io.ObjectInput;
import java.io.ObjectOutput;
+import java.io.Serializable;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.HashSet;
@@ -65,14 +66,15 @@
private static final Logger LOGGER =
Util.getLogger(Util.FACES_LOGGER + Util.APPLICATION_LOGGER);
+ private static final Object[] STATE_PLACEHOLDER = new Object[0];
private HashMap<String, Boolean> responseStateManagerInfo = null;
- private char requestIdSerial = 0;
+ private char requestIdSerial;
/** Number of views in logical view to be saved in session. */
- private int noOfViews = 0;
- private int noOfViewsInLogicalView = 0;
+ private int noOfViews;
+ private int noOfViewsInLogicalView;
private Map<String,Class<?>> classMap =
new ConcurrentHashMap<String,Class<?>>(32);
@@ -86,11 +88,7 @@
UIViewRoot viewRoot = null;
if (isSavingStateInClient(context)) {
- viewRoot = restoreTree(context, viewId, renderKitId);
-
- if (viewRoot != null) {
- restoreState(context, viewRoot, renderKitId);
- }
+ viewRoot = restoreTree(context, viewId, renderKitId);
} else {
// restore tree from session.
// The ResponseStateManager implementation may be using the new
@@ -172,8 +170,8 @@
// of the TreeNode instances. This is a problem
// for servers that persist session data since
// UIComponent instances are not serializable.
- viewRoot = restoreTree(((Object[]) stateArray[0]).clone());
- viewRoot.processRestoreState(context, stateArray[1]);
+ viewRoot = restoreTree(((Object[]) stateArray[0]).clone(),
+ context);
if (LOGGER.isLoggable(Level.FINE)) {
LOGGER.fine("End restoring view in session for viewId "
@@ -209,8 +207,7 @@
+ viewRoot.getViewId());
}
List<TreeNode> treeList = new ArrayList<TreeNode>(32);
- captureChild(treeList, 0, viewRoot);
- Object state = viewRoot.processSaveState(context);
+ captureChild(treeList, 0, viewRoot, context);
Object[] tree = treeList.toArray();
if (LOGGER.isLoggable(Level.FINE)) {
@@ -274,13 +271,13 @@
// reuse the array if possible
if (stateArray != null) {
stateArray[0] = tree;
- stateArray[1] = state;
+ stateArray[1] = STATE_PLACEHOLDER;
} else {
- actualMap.put(idInActualMap, new Object[] { tree, state });
+ actualMap.put(idInActualMap, new Object[] { tree, STATE_PLACEHOLDER });
}
}
} else {
- result = new SerializedView(tree, state);
+ result = new SerializedView(tree, STATE_PLACEHOLDER);
}
return result;
@@ -431,40 +428,48 @@
- private static void captureChild(List<TreeNode> tree, int parent,
- UIComponent c) {
+ private static void captureChild(List<TreeNode> tree,
+ int parent,
+ UIComponent c,
+ FacesContext ctx) {
if (!c.isTransient()) {
- TreeNode n = new TreeNode(parent, c);
+ TreeNode n = new TreeNode(parent, c, ctx);
int pos = tree.size();
tree.add(n);
- captureRest(tree, pos, c);
+ captureRest(tree, pos, c, ctx);
}
}
- private static void captureFacet(List<TreeNode> tree, int parent, String name,
- UIComponent c) {
+ private static void captureFacet(List<TreeNode> tree,
+ int parent,
+ String name,
+ UIComponent c,
+ FacesContext ctx) {
if (!c.isTransient()) {
- FacetNode n = new FacetNode(parent, name, c);
+ FacetNode n = new FacetNode(parent, name, c, ctx);
int pos = tree.size();
tree.add(n);
- captureRest(tree, pos, c);
+ captureRest(tree, pos, c, ctx);
}
}
- private static void captureRest(List<TreeNode> tree, int pos, UIComponent c) {
+ private static void captureRest(List<TreeNode> tree,
+ int pos,
+ UIComponent c,
+ FacesContext ctx) {
// store children
int sz = c.getChildCount();
if (sz > 0) {
List<UIComponent> child = c.getChildren();
for (int i = 0; i < sz; i++) {
- captureChild(tree, pos, child.get(i));
+ captureChild(tree, pos, child.get(i), ctx);
}
}
@@ -475,7 +480,8 @@
captureFacet(tree,
pos,
entry.getKey(),
- entry.getValue());
+ entry.getValue(),
+ ctx);
}
}
@@ -516,7 +522,8 @@
}
- private UIComponent newInstance(TreeNode n) throws FacesException {
+ private UIComponent newInstance(TreeNode n, FacesContext ctx)
+ throws FacesException {
try {
Class<?> t = classMap.get(n.componentType);
@@ -531,31 +538,15 @@
UIComponent c = (UIComponent) t.newInstance();
c.setId(n.id);
+ if (!n.trans) {
+ c.restoreState(ctx, n.state);
+ }
return c;
} catch (Exception e) {
throw new FacesException(e);
}
- }
-
- @SuppressWarnings("deprecation")
- private void restoreState(FacesContext context,
- UIViewRoot root,
- String renderKitId) {
- ResponseStateManager rsm =
- RenderKitUtils.getResponseStateManager(context, renderKitId);
- Object state;
- if (hasDeclaredMethod(renderKitId,
- rsm,
- "getState")) {
- Object[] stateArray =
- (Object[]) rsm.getState(context, root.getViewId());
- state = stateArray[1];
- } else {
- state = rsm.getComponentStateToRestore(context);
- }
- root.processRestoreState(context, state);
- }
+ }
@SuppressWarnings("deprecation")
@@ -581,7 +572,7 @@
return null;
}
- return restoreTree(treeStructure);
+ return restoreTree(treeStructure, context);
}
private String createUniqueRequestId() {
@@ -594,7 +585,8 @@
}
- private UIViewRoot restoreTree(Object[] tree) throws FacesException {
+ private UIViewRoot restoreTree(Object[] tree, FacesContext ctx)
+ throws FacesException {
UIComponent c;
FacetNode fn;
@@ -602,8 +594,8 @@
for (int i = 0; i < tree.length; i++) {
if (tree[i]instanceof FacetNode) {
fn = (FacetNode) tree[i];
- c = newInstance(fn);
- tree[i] = c;
+ c = newInstance(fn, ctx);
+ tree[i] = c;
if (i != fn.parent) {
((UIComponent) tree[fn.parent]).getFacets()
.put(fn.facetName, c);
@@ -611,7 +603,7 @@
} else {
tn = (TreeNode) tree[i];
- c = newInstance(tn);
+ c = newInstance(tn, ctx);
tree[i] = c;
if (i != tn.parent) {
((UIComponent) tree[tn.parent]).getChildren().add(c);
@@ -629,6 +621,8 @@
public String componentType;
public String id;
+ public Serializable state;
+ public boolean trans;
public int parent;
@@ -641,11 +635,15 @@
public TreeNode() { }
- public TreeNode(int parent, UIComponent c) {
+ public TreeNode(int parent, UIComponent c, FacesContext ctx) {
this.parent = parent;
this.id = c.getId();
- this.componentType = c.getClass().getName();
+ this.componentType = c.getClass().getName();
+ this.trans = c.isTransient();
+ if (!trans) {
+ this.state = (Serializable) c.saveState(ctx);
+ }
}
@@ -656,11 +654,15 @@
out.writeInt(this.parent);
out.writeUTF(this.componentType);
+ out.writeBoolean(this.trans);
if (this.id != null) {
out.writeUTF(this.id);
} else {
out.writeUTF(NULL_ID);
}
+ if (!trans) {
+ out.writeObject(state);
+ }
}
@@ -670,11 +672,14 @@
this.parent = in.readInt();
this.componentType = in.readUTF();
+ this.trans = in.readBoolean();
this.id = in.readUTF();
if (id.length() == 0) {
id = null;
+ }
+ if (!trans) {
+ state = (Serializable) in.readObject();
}
-
}
@@ -692,9 +697,12 @@
public FacetNode() { }
- public FacetNode(int parent, String name, UIComponent c) {
+ public FacetNode(int parent,
+ String name,
+ UIComponent c,
+ FacesContext ctx) {
- super(parent, c);
+ super(parent, c, ctx);
this.facetName = name;
}
Index: src/com/sun/faces/config/WebConfiguration.java
===================================================================
RCS file: /cvs/javaserverfaces-sources/jsf-ri/src/com/sun/faces/config/WebConfiguration.java,v
retrieving revision 1.13
diff -u -r1.13 WebConfiguration.java
--- src/com/sun/faces/config/WebConfiguration.java 30 Aug 2006 21:53:45 -0000 1.13
+++ src/com/sun/faces/config/WebConfiguration.java 6 Sep 2006 17:40:29 -0000
@@ -99,7 +99,7 @@
* the result of FacesContext.getCurrentInstance().getExternalContext()
* to {_at_link #getInstance(javax.faces.context.ExternalContext)}.
* @return the WebConfiguration for this application or <code>null</code>
- * if no WebConfiguration could be located
+ * if no FacesContext is available.
*/
public static WebConfiguration getInstance() {
@@ -115,14 +115,38 @@
/**
* Return the WebConfiguration instance for this application.
- * @param extContext the external context for this request
- * @return the WebConfiguration for this application or <code>null</code>
- * if no WebConfiguration could be located
+ * @param extContext the ExternalContext for this request
+ * @return the WebConfiguration for this application
*/
public static WebConfiguration getInstance(ExternalContext extContext) {
- return (WebConfiguration) extContext.getApplicationMap()
+ WebConfiguration config = (WebConfiguration) extContext.getApplicationMap()
.get(WEB_CONFIG_KEY);
+ if (config == null) {
+ return getInstance((ServletContext) extContext.getContext());
+ } else {
+ return config;
+ }
+
+ }
+
+
+ /**
+ * Return the WebConfiguration instance for this application.
+ * @param servletContext the ServletContext
+ * @return the WebConfiguration for this application or <code>null</code>
+ * if no WebConfiguration could be located
+ */
+ public static WebConfiguration getInstance(ServletContext servletContext) {
+
+ WebConfiguration webConfig = (WebConfiguration)
+ servletContext.getAttribute(WEB_CONFIG_KEY);
+
+ if (webConfig == null) {
+ webConfig = new WebConfiguration(servletContext);
+ servletContext.setAttribute(WEB_CONFIG_KEY, webConfig);
+ }
+ return webConfig;
}
@@ -225,20 +249,6 @@
}
- static WebConfiguration getInstance(ServletContext servletContext) {
-
- WebConfiguration webConfig = (WebConfiguration)
- servletContext.getAttribute(WEB_CONFIG_KEY);
-
- if (webConfig == null) {
- webConfig = new WebConfiguration(servletContext);
- servletContext.setAttribute(WEB_CONFIG_KEY, webConfig);
- }
- return webConfig;
-
- }
-
-
// --------------------------------------------------------- Private Methods
@@ -665,6 +675,10 @@
ExternalizeJavaScript(
"com.sun.faces.externalizeJavaScript",
false
+ ),
+ SendPoweredByHeader(
+ "com.sun.faces.sendPoweredByHeader",
+ true
);
private BooleanWebContextInitParameter alternate;
Index: src/com/sun/faces/context/ExternalContextImpl.java
===================================================================
RCS file: /cvs/javaserverfaces-sources/jsf-ri/src/com/sun/faces/context/ExternalContextImpl.java,v
retrieving revision 1.51
diff -u -r1.51 ExternalContextImpl.java
--- src/com/sun/faces/context/ExternalContextImpl.java 5 Sep 2006 22:52:31 -0000 1.51
+++ src/com/sun/faces/context/ExternalContextImpl.java 6 Sep 2006 17:40:29 -0000
@@ -67,6 +67,8 @@
import java.util.logging.Logger;
import com.sun.faces.RIConstants;
+import com.sun.faces.config.WebConfiguration;
+import com.sun.faces.config.WebConfiguration.BooleanWebContextInitParameter;
import com.sun.faces.util.MessageUtils;
import com.sun.faces.util.TypedCollections;
import com.sun.faces.util.Util;
@@ -143,6 +145,12 @@
}
}
this.response = response;
+ WebConfiguration config = WebConfiguration.getInstance(sc);
+ if (config
+ .getBooleanContextInitParameter(BooleanWebContextInitParameter.SendPoweredByHeader)) {
+ ((HttpServletResponse) response)
+ .addHeader("X-Powered-By", "JSF/1.2");
+ }
// Store this in request scope so jsf-api can access it.
this.getRequestMap().put(EXTERNALCONTEXT_IMPL_ATTR_NAME, this);
Index: src/com/sun/faces/lifecycle/LifecycleImpl.java
===================================================================
RCS file: /cvs/javaserverfaces-sources/jsf-ri/src/com/sun/faces/lifecycle/LifecycleImpl.java,v
retrieving revision 1.67
diff -u -r1.67 LifecycleImpl.java
--- src/com/sun/faces/lifecycle/LifecycleImpl.java 15 Jun 2006 17:46:31 -0000 1.67
+++ src/com/sun/faces/lifecycle/LifecycleImpl.java 6 Sep 2006 17:40:29 -0000
@@ -110,9 +110,9 @@
break;
}
- phase((PhaseId) PhaseId.VALUES.get(i), phases[i], context);
+ phase(PhaseId.VALUES.get(i), phases[i], context);
- if (reload((PhaseId) PhaseId.VALUES.get(i), context)) {
+ if (reload(PhaseId.VALUES.get(i), context)) {
if (LOGGER.isLoggable(Level.FINE)) {
LOGGER.fine("Skipping rest of execute() because of a reload");
}
Index: src/com/sun/faces/renderkit/ResponseStateManagerImpl.java
===================================================================
RCS file: /cvs/javaserverfaces-sources/jsf-ri/src/com/sun/faces/renderkit/ResponseStateManagerImpl.java,v
retrieving revision 1.37
diff -u -r1.37 ResponseStateManagerImpl.java
--- src/com/sun/faces/renderkit/ResponseStateManagerImpl.java 29 Aug 2006 06:13:00 -0000 1.37
+++ src/com/sun/faces/renderkit/ResponseStateManagerImpl.java 6 Sep 2006 17:40:29 -0000
@@ -96,19 +96,7 @@
super();
init();
- }
-
-
- /** @see {_at_link ResponseStateManager#getComponentStateToRestore(javax.faces.context.FacesContext)} */
- @Override
- @SuppressWarnings("deprecation")
- public Object getComponentStateToRestore(FacesContext context) {
-
- // requestMap is a local variable so we don't need to synchronize
- return context.getExternalContext().getRequestMap()
- .remove(FACES_VIEW_STATE);
-
- }
+ }
/** @see {_at_link ResponseStateManager#isPostback(javax.faces.context.FacesContext)} */
@@ -162,11 +150,11 @@
ois = serialProvider.createObjectInputStream(bis);
}
Object structure = ois.readObject();
- Object state = ois.readObject();
+ //Object state = ois.readObject();
ois.close();
- storeStateInRequest(context, state);
+ //storeStateInRequest(context, state);
return structure;
} catch (java.io.OptionalDataException ode) {
@@ -234,7 +222,7 @@
}
oos.writeObject(view.getStructure());
- oos.writeObject(view.getState());
+ //oos.writeObject(view.getState());
oos.flush();
oos.close();
@@ -264,25 +252,7 @@
writeRenderKitIdField(context, writer);
- }
-
-
- /**
- * <p>Store the state for this request into a temporary attribute
- * within the same request.</p>
- *
- * @param context the <code>FacesContext</code> of the current request
- * @param state the view state
- */
- private void storeStateInRequest(FacesContext context, Object state) {
-
- // store the state object temporarily in request scope
- // until it is processed by getComponentStateToRestore
- // which resets it.
- context.getExternalContext().getRequestMap()
- .put(FACES_VIEW_STATE, state);
-
- }
+ }
/**