Author: alexsmirnov
Date: 2007-10-16 19:18:22 -0400 (Tue, 16 Oct 2007)
New Revision: 3410
Added:
trunk/framework/api/src/main/java/org/ajax4jsf/application/StateHolder.java
trunk/framework/impl/src/main/java/org/ajax4jsf/application/TreeStrutureNode.java
trunk/ui/inputnumber-spinner/src/main/config/resources/
trunk/ui/inputnumber-spinner/src/main/config/resources/resources-config.xml
Modified:
trunk/framework/impl/src/main/java/org/ajax4jsf/application/AjaxStateHolder.java
trunk/framework/impl/src/main/java/org/ajax4jsf/application/AjaxStateManager.java
trunk/framework/test/src/test/java/org/ajax4jsf/application/AjaxStateHolderTest.java
trunk/framework/test/src/test/java/org/ajax4jsf/application/AjaxStateManagerTest.java
trunk/samples/pom.xml
trunk/ui/paint2D/src/main/java/org/richfaces/renderkit/html/Paint2DResource.java
Log:
Unit tests for a Ajax StateManager implementation.
Added: trunk/framework/api/src/main/java/org/ajax4jsf/application/StateHolder.java
===================================================================
--- trunk/framework/api/src/main/java/org/ajax4jsf/application/StateHolder.java
(rev 0)
+++ trunk/framework/api/src/main/java/org/ajax4jsf/application/StateHolder.java 2007-10-16
23:18:22 UTC (rev 3410)
@@ -0,0 +1,9 @@
+package org.ajax4jsf.application;
+
+public interface StateHolder {
+
+ public Object getState(String viewId, Object sequence);
+
+ public void saveState(String viewId, Object sequence, Object state);
+
+}
\ No newline at end of file
Property changes on:
trunk/framework/api/src/main/java/org/ajax4jsf/application/StateHolder.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Name: svn:keywords
+ Date Revision Author
Modified:
trunk/framework/impl/src/main/java/org/ajax4jsf/application/AjaxStateHolder.java
===================================================================
---
trunk/framework/impl/src/main/java/org/ajax4jsf/application/AjaxStateHolder.java 2007-10-16
21:08:17 UTC (rev 3409)
+++
trunk/framework/impl/src/main/java/org/ajax4jsf/application/AjaxStateHolder.java 2007-10-16
23:18:22 UTC (rev 3410)
@@ -18,7 +18,7 @@
* @author asmirnov
*
*/
-public class AjaxStateHolder implements Serializable {
+public class AjaxStateHolder implements Serializable, StateHolder {
private static final Log _log = LogFactory.getLog(AjaxStateHolder.class);
/**
@@ -36,7 +36,7 @@
this.numberOfViews = numberOfViews;
}
- public static AjaxStateHolder getInstance(FacesContext context) {
+ public static StateHolder getInstance(FacesContext context) {
if (null == context) {
throw new NullPointerException(
"FacesContext parameter for get view states object is null");
@@ -47,9 +47,9 @@
if (_log.isDebugEnabled()) {
_log.debug("Request for a view states holder instance");
}
- AjaxStateHolder instance = null;
+ StateHolder instance = null;
synchronized (session) {
- instance = (AjaxStateHolder) sessionMap.get(STATE_HOLDER);
+ instance = (StateHolder) sessionMap.get(STATE_HOLDER);
if (null == instance) {
// Create and store in session new state holder.
int numbersOfViewsInSession = ContextInitParameters
@@ -72,6 +72,9 @@
return instance;
}
+ /* (non-Javadoc)
+ * @see org.ajax4jsf.application.StateHolder#getState(java.lang.String,
java.lang.Object)
+ */
public Object getState(String viewId, Object sequence) {
if (null == viewId) {
throw new NullPointerException(
@@ -97,6 +100,9 @@
return state;
}
+ /* (non-Javadoc)
+ * @see org.ajax4jsf.application.StateHolder#saveState(java.lang.String,
java.lang.Object, java.lang.Object)
+ */
public void saveState(String viewId, Object sequence, Object state) {
if (null == viewId) {
throw new NullPointerException(
Modified:
trunk/framework/impl/src/main/java/org/ajax4jsf/application/AjaxStateManager.java
===================================================================
---
trunk/framework/impl/src/main/java/org/ajax4jsf/application/AjaxStateManager.java 2007-10-16
21:08:17 UTC (rev 3409)
+++
trunk/framework/impl/src/main/java/org/ajax4jsf/application/AjaxStateManager.java 2007-10-16
23:18:22 UTC (rev 3410)
@@ -21,25 +21,13 @@
package org.ajax4jsf.application;
-import java.io.Externalizable;
import java.io.IOException;
-import java.io.ObjectInput;
-import java.io.ObjectOutput;
import java.lang.reflect.Constructor;
-import java.util.ArrayList;
-import java.util.HashMap;
import java.util.HashSet;
-import java.util.Iterator;
-import java.util.List;
-import java.util.Map;
-import java.util.Set;
-import java.util.Map.Entry;
import javax.faces.FactoryFinder;
import javax.faces.application.StateManager;
-import javax.faces.component.UIComponent;
import javax.faces.component.UIViewRoot;
-import javax.faces.context.ExternalContext;
import javax.faces.context.FacesContext;
import javax.faces.render.RenderKit;
import javax.faces.render.RenderKitFactory;
@@ -47,7 +35,6 @@
import org.ajax4jsf.context.AjaxContext;
import org.ajax4jsf.event.AjaxPhaseListener;
-import org.apache.commons.collections.map.LRUMap;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
@@ -57,15 +44,52 @@
*/
public class AjaxStateManager extends StateManager {
+ private final class SeamStateManagerWrapper extends StateManager {
+ protected Object getComponentStateToSave(FacesContext arg0) {
+ // do nothing
+ return null;
+ }
+
+ protected Object getTreeStructureToSave(FacesContext arg0) {
+ // do nothing
+ return null;
+ }
+
+ protected void restoreComponentState(FacesContext arg0,
+ UIViewRoot arg1, String arg2) {
+ // do nothing
+
+ }
+
+ protected UIViewRoot restoreTreeStructure(FacesContext arg0,
+ String arg1, String arg2) {
+ // do nothing
+ return null;
+ }
+
+ public UIViewRoot restoreView(FacesContext arg0, String arg1,
+ String arg2) {
+ // do nothing
+ return null;
+ }
+
+ public SerializedView saveSerializedView(FacesContext arg0) {
+ // delegate to enclosed class method.
+ return buildSerializedView(arg0);
+ }
+
+ public void writeState(FacesContext arg0, SerializedView arg1)
+ throws IOException {
+ // do nothing
+ }
+ }
+
private static final Class[] STATE_MANAGER_ARGUMENTS = new Class[] { StateManager.class
};
public static final int DEFAULT_NUMBER_OF_VIEWS = 16;
- private static final String VIEW_STATES_MAP = AjaxStateManager.class
- .getName()
- + ".VIEW_STATES_MAP";
- private static final Object VIEW_SEQUENCE = AjaxStateManager.class
+ public static final String VIEW_SEQUENCE = AjaxStateManager.class
.getName()
+ ".VIEW_SEQUENCE";
@@ -102,50 +126,7 @@
Constructor constructor = seamStateManagerClass
.getConstructor(STATE_MANAGER_ARGUMENTS);
seamStateManager = (StateManager) constructor
- .newInstance(new Object[] { new StateManager() {
-
- protected Object getComponentStateToSave(
- FacesContext arg0) {
- // do nothing
- return null;
- }
-
- protected Object getTreeStructureToSave(
- FacesContext arg0) {
- // do nothing
- return null;
- }
-
- protected void restoreComponentState(FacesContext arg0,
- UIViewRoot arg1, String arg2) {
- // do nothing
-
- }
-
- protected UIViewRoot restoreTreeStructure(
- FacesContext arg0, String arg1, String arg2) {
- // do nothing
- return null;
- }
-
- public UIViewRoot restoreView(FacesContext arg0,
- String arg1, String arg2) {
- // do nothing
- return null;
- }
-
- public SerializedView saveSerializedView(
- FacesContext arg0) {
- // delegate to enclosed class method.
- return buildSerializedView(arg0);
- }
-
- public void writeState(FacesContext arg0,
- SerializedView arg1) throws IOException {
- // do nothing
- }
-
- } });
+ .newInstance(new Object[] { new SeamStateManagerWrapper() });
if (_log.isDebugEnabled()) {
_log.debug("Create instance of the SeamStateManager");
}
@@ -163,7 +144,9 @@
* @see
javax.faces.application.StateManager#getComponentStateToSave(javax.faces.context.FacesContext)
*/
protected Object getComponentStateToSave(FacesContext context) {
- throw new UnsupportedOperationException();
+ Object treeState = context.getViewRoot().processSaveState(context);
+ Object state[] = { treeState, getAdditionalState(context) };
+ return state;
}
/*
@@ -172,7 +155,9 @@
* @see
javax.faces.application.StateManager#getTreeStructureToSave(javax.faces.context.FacesContext)
*/
protected Object getTreeStructureToSave(FacesContext context) {
- throw new UnsupportedOperationException();
+ TreeStrutureNode treeStructure = new TreeStrutureNode();
+ treeStructure.apply(context, context.getViewRoot(), new HashSet());
+ return treeStructure;
}
/*
@@ -253,59 +238,9 @@
protected Object[] restoreStateFromSession(FacesContext context,
String viewId, String renderKitId) {
- Object[] restoredState = null;
- Object id = getRenderKit(context, renderKitId)
- .getResponseStateManager().getTreeStructureToRestore(context,
- viewId);
- ExternalContext externalContext = context.getExternalContext();
- Object session = externalContext.getSession(false);
- if (null == session) {
- if (_log.isDebugEnabled()) {
- _log.debug("Can't restore view state : session expired");
- }
- } else {
- synchronized (session) {
- LRUMap viewStates = (LRUMap) externalContext.getSessionMap()
- .get(VIEW_STATES_MAP);
- if (null != viewStates) {
- LRUMap logicalStates = (LRUMap) viewStates.get(viewId);
- if (null != logicalStates) {
- if (null != id) {
- restoredState = (Object[]) logicalStates.get(id);
- externalContext.getRequestMap().put(VIEW_SEQUENCE,
- id);
- if (null == restoredState) {
- if (_log.isDebugEnabled()) {
- _log
- .debug("No saved view state found for a Id "
- + id
- + ". Restore last saved state");
- }
- restoredState = (Object[]) logicalStates
- .get(logicalStates.firstKey());
- }
- } else {
- if (_log.isDebugEnabled()) {
- _log
- .debug("No version Id for a saved view state in request. Restore last
saved state");
- }
- restoredState = (Object[]) logicalStates
- .get(logicalStates.firstKey());
- }
- } else if (_log.isDebugEnabled()) {
- _log
- .debug("Can't restore view state : no saved states for a ViewId "
- + viewId);
- }
-
- } else if (_log.isDebugEnabled()) {
- _log
- .debug("Can't restore view state : no saved view states in
session");
- }
-
- }
- }
-
+ Object id = restoreLogicalViewId(context, viewId, renderKitId);
+ StateHolder stateHolder = getStateHolder(context);
+ Object[] restoredState = (Object[]) stateHolder.getState(viewId, id);
return restoredState;
}
@@ -326,10 +261,8 @@
SerializedView serializedView = null;
UIViewRoot viewRoot = context.getViewRoot();
if (!viewRoot.isTransient()) {
- TreeStrutureNode treeStructure = new TreeStrutureNode();
- treeStructure.apply(context, viewRoot, new HashSet());
- Object treeState = viewRoot.processSaveState(context);
- Object state[] = { treeState, getAdditionalState(context) };
+ TreeStrutureNode treeStructure = (TreeStrutureNode) getTreeStructureToSave(context);
+ Object state = getComponentStateToSave(context);
if (isSavingStateInClient(context)) {
serializedView = new SerializedView(treeStructure, state);
} else {
@@ -351,30 +284,22 @@
Object treeStructure, Object state) {
SerializedView serializedView;
UIViewRoot viewRoot = context.getViewRoot();
- ExternalContext externalContext = context.getExternalContext();
- Object session = externalContext.getSession(true);
- synchronized (session) {
- LRUMap viewStates = (LRUMap) externalContext.getSessionMap().get(
- VIEW_STATES_MAP);
- if (null == viewStates) {
- viewStates = new LRUMap(getNumberOfViews(externalContext));
- externalContext.getSessionMap()
- .put(VIEW_STATES_MAP, viewStates);
- }
- Object id = getNextViewId(context);
- LRUMap logicalViewsMap = (LRUMap) viewStates.get(viewRoot
- .getViewId());
- if (null == logicalViewsMap) {
- logicalViewsMap = new LRUMap(getNumberOfViews(externalContext));
- }
- // Renew last seen view.
- viewStates.put(viewRoot.getViewId(), logicalViewsMap);
- logicalViewsMap.put(id, new Object[] { treeStructure, state });
- serializedView = new SerializedView(id, null);
- }
+ StateHolder stateHolder = getStateHolder(context);
+ Object id = getLogicalViewId(context);
+ stateHolder.saveState(viewRoot.getViewId(), id, new Object[] {
+ treeStructure, state });
+ serializedView = new SerializedView(id, null);
return serializedView;
}
+ /**
+ * @param context
+ * @return
+ */
+ protected StateHolder getStateHolder(FacesContext context) {
+ return AjaxStateHolder.getInstance(context);
+ }
+
protected Object getAdditionalState(FacesContext context) {
return null;
}
@@ -383,7 +308,31 @@
}
- protected Object getNextViewId(FacesContext context) {
+ /**
+ * Restore logical view id from request.
+ * @param context
+ * @param viewId
+ * @param renderKitId
+ * @return
+ */
+ protected Object restoreLogicalViewId(FacesContext context, String viewId,
+ String renderKitId) {
+ Object id = getRenderKit(context, renderKitId)
+ .getResponseStateManager().getTreeStructureToRestore(context,
+ viewId);
+ if (null != id) {
+ context.getExternalContext().getRequestMap().put(VIEW_SEQUENCE, id);
+ }
+ return id;
+ }
+
+ /**
+ * Return logical Id for current request view state. For a faces requests, generate
sequence numbers.
+ * For a ajax request, attempt to re-use id from request submit.
+ * @param context
+ * @return
+ */
+ protected Object getLogicalViewId(FacesContext context) {
AjaxContext ajaxContext = AjaxContext.getCurrentInstance(context);
if (ajaxContext.isAjaxRequest(context)) {
Object id = context.getExternalContext().getRequestMap().get(
@@ -400,9 +349,6 @@
return UIViewRoot.UNIQUE_ID_PREFIX + ((int) viewSequence);
}
- protected int getNumberOfViews(ExternalContext externalContext) {
- return DEFAULT_NUMBER_OF_VIEWS;
- }
protected RenderKit getRenderKit(FacesContext context, String renderKitId) {
RenderKit renderKit = context.getRenderKit();
@@ -414,201 +360,4 @@
return renderKit;
}
- protected static final class TreeStrutureNode implements Externalizable {
- /**
- * TODO - implement Externalizable to reduce serialized state.
- */
- private static final long serialVersionUID = -9038742487716977911L;
-
- private static final String NULL_ID = "";
-
- private Map facets = null;
-
- private List children = null;
-
- private String type;
-
- private String id;
-
- public TreeStrutureNode() {
- }
-
- public void apply(FacesContext context, UIComponent component,
- Set uniqueIds) {
- type = component.getClass().getName();
- id = component.getId();
- String clientId = component.getClientId(context);
- if (!uniqueIds.add(clientId)) {
- throw new IllegalStateException("duplicate Id for a component "
- + clientId);
- }
- Map componentFacets = component.getFacets();
- for (Iterator i = componentFacets.entrySet().iterator(); i
- .hasNext();) {
- Entry element = (Entry) i.next();
- UIComponent f = (UIComponent) element.getValue();
- if (!f.isTransient()) {
- TreeStrutureNode facet = new TreeStrutureNode();
- facet.apply(context, f, uniqueIds);
- if (null == facets) {
- facets = new HashMap();
- }
- facets.put(element.getKey(), facet);
-
- }
- }
- for (Iterator i = component.getChildren().iterator(); i.hasNext();) {
- UIComponent child = (UIComponent) i.next();
- if (!child.isTransient()) {
- TreeStrutureNode t = new TreeStrutureNode();
- t.apply(context, child, uniqueIds);
- if (null == children) {
- children = new ArrayList();
- }
- children.add(t);
-
- }
- }
- }
-
- public UIComponent restore(ComponentsLoader loader) {
- UIComponent component;
- component = loader.createComponent(type);
- component.setId(id);
- if (null != facets) {
- for (Iterator i = facets.entrySet().iterator(); i.hasNext();) {
- Entry element = (Entry) i.next();
- UIComponent facet = ((TreeStrutureNode) element.getValue())
- .restore(loader);
- component.getFacets().put(element.getKey(), facet);
- }
-
- }
- if (null != children) {
- for (Iterator i = children.iterator(); i.hasNext();) {
- TreeStrutureNode node = (TreeStrutureNode) i.next();
- UIComponent child = node.restore(loader);
- component.getChildren().add(child);
- }
-
- }
- return component;
- }
-
- /**
- * @return the facets
- */
- public Map getFacets() {
- return facets;
- }
-
- /**
- * @param facets
- * the facets to set
- */
- public void setFacets(Map facets) {
- this.facets = facets;
- }
-
- /**
- * @return the children
- */
- public List getChildren() {
- return children;
- }
-
- /**
- * @param children
- * the children to set
- */
- public void setChildren(List children) {
- this.children = children;
- }
-
- /**
- * @return the type
- */
- public String getType() {
- return type;
- }
-
- /**
- * @param type
- * the type to set
- */
- public void setType(String type) {
- this.type = type;
- }
-
- /**
- * @return the id
- */
- public String getId() {
- return id;
- }
-
- /**
- * @param id
- * the id to set
- */
- public void setId(String id) {
- this.id = id;
- }
-
- public void readExternal(ObjectInput in) throws IOException,
- ClassNotFoundException {
- type = in.readUTF();
- id = in.readUTF();
- if (NULL_ID.equals(id)) {
- id = null;
- }
- int facetsSize = in.readInt();
- if (facetsSize > 0) {
- facets = new HashMap(facetsSize);
- for (int i = 0; i < facetsSize; i++) {
- String facetName = in.readUTF();
- TreeStrutureNode facet = new TreeStrutureNode();
- facet.readExternal(in);
- facets.put(facetName, facet);
- }
- }
- int childrenSize = in.readInt();
- if (childrenSize > 0) {
- children = new ArrayList(childrenSize);
- for (int i = 0; i < childrenSize; i++) {
- TreeStrutureNode child = new TreeStrutureNode();
- child.readExternal(in);
- children.add(child);
- }
- }
- }
-
- public void writeExternal(ObjectOutput out) throws IOException {
- out.writeUTF(type);
- out.writeUTF(null == id ? NULL_ID : id);
- if (null != facets) {
- out.writeInt(facets.size());
- for (Iterator i = facets.entrySet().iterator(); i.hasNext();) {
- Map.Entry entry = (Map.Entry) i.next();
- out.writeUTF((String) entry.getKey());
- TreeStrutureNode node = (TreeStrutureNode) entry.getValue();
- node.writeExternal(out);
- }
-
- } else {
- out.writeInt(0);
- }
- if (null != children) {
- out.writeInt(children.size());
- for (Iterator i = children.iterator(); i.hasNext();) {
- TreeStrutureNode child = (TreeStrutureNode) i.next();
- child.writeExternal(out);
- }
-
- } else {
- out.writeInt(0);
- }
- }
- }
-
}
Added: trunk/framework/impl/src/main/java/org/ajax4jsf/application/TreeStrutureNode.java
===================================================================
--- trunk/framework/impl/src/main/java/org/ajax4jsf/application/TreeStrutureNode.java
(rev 0)
+++
trunk/framework/impl/src/main/java/org/ajax4jsf/application/TreeStrutureNode.java 2007-10-16
23:18:22 UTC (rev 3410)
@@ -0,0 +1,220 @@
+/**
+ *
+ */
+package org.ajax4jsf.application;
+
+import java.io.Externalizable;
+import java.io.IOException;
+import java.io.ObjectInput;
+import java.io.ObjectOutput;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+import java.util.Map.Entry;
+
+import javax.faces.component.UIComponent;
+import javax.faces.context.FacesContext;
+
+/**
+ * @author asmirnov
+ *
+ */
+final class TreeStrutureNode implements Externalizable {
+ /**
+ * TODO - implement Externalizable to reduce serialized state.
+ */
+ private static final long serialVersionUID = -9038742487716977911L;
+
+ private static final String NULL_ID = "";
+
+ private Map facets = null;
+
+ private List children = null;
+
+ private String type;
+
+ private String id;
+
+ public TreeStrutureNode() {
+ }
+
+ public void apply(FacesContext context, UIComponent component,
+ Set uniqueIds) {
+ type = component.getClass().getName();
+ id = component.getId();
+ String clientId = component.getClientId(context);
+ if (!uniqueIds.add(clientId)) {
+ throw new IllegalStateException("duplicate Id for a component "
+ + clientId);
+ }
+ Map componentFacets = component.getFacets();
+ for (Iterator i = componentFacets.entrySet().iterator(); i
+ .hasNext();) {
+ Entry element = (Entry) i.next();
+ UIComponent f = (UIComponent) element.getValue();
+ if (!f.isTransient()) {
+ TreeStrutureNode facet = new TreeStrutureNode();
+ facet.apply(context, f, uniqueIds);
+ if (null == facets) {
+ facets = new HashMap();
+ }
+ facets.put(element.getKey(), facet);
+
+ }
+ }
+ for (Iterator i = component.getChildren().iterator(); i.hasNext();) {
+ UIComponent child = (UIComponent) i.next();
+ if (!child.isTransient()) {
+ TreeStrutureNode t = new TreeStrutureNode();
+ t.apply(context, child, uniqueIds);
+ if (null == children) {
+ children = new ArrayList();
+ }
+ children.add(t);
+
+ }
+ }
+ }
+
+ public UIComponent restore(ComponentsLoader loader) {
+ UIComponent component;
+ component = loader.createComponent(type);
+ component.setId(id);
+ if (null != facets) {
+ for (Iterator i = facets.entrySet().iterator(); i.hasNext();) {
+ Entry element = (Entry) i.next();
+ UIComponent facet = ((TreeStrutureNode) element.getValue())
+ .restore(loader);
+ component.getFacets().put(element.getKey(), facet);
+ }
+
+ }
+ if (null != children) {
+ for (Iterator i = children.iterator(); i.hasNext();) {
+ TreeStrutureNode node = (TreeStrutureNode) i.next();
+ UIComponent child = node.restore(loader);
+ component.getChildren().add(child);
+ }
+
+ }
+ return component;
+ }
+
+ /**
+ * @return the facets
+ */
+ public Map getFacets() {
+ return facets;
+ }
+
+ /**
+ * @param facets
+ * the facets to set
+ */
+ public void setFacets(Map facets) {
+ this.facets = facets;
+ }
+
+ /**
+ * @return the children
+ */
+ public List getChildren() {
+ return children;
+ }
+
+ /**
+ * @param children
+ * the children to set
+ */
+ public void setChildren(List children) {
+ this.children = children;
+ }
+
+ /**
+ * @return the type
+ */
+ public String getType() {
+ return type;
+ }
+
+ /**
+ * @param type
+ * the type to set
+ */
+ public void setType(String type) {
+ this.type = type;
+ }
+
+ /**
+ * @return the id
+ */
+ public String getId() {
+ return id;
+ }
+
+ /**
+ * @param id
+ * the id to set
+ */
+ public void setId(String id) {
+ this.id = id;
+ }
+
+ public void readExternal(ObjectInput in) throws IOException,
+ ClassNotFoundException {
+ type = in.readUTF();
+ id = in.readUTF();
+ if (NULL_ID.equals(id)) {
+ id = null;
+ }
+ int facetsSize = in.readInt();
+ if (facetsSize > 0) {
+ facets = new HashMap(facetsSize);
+ for (int i = 0; i < facetsSize; i++) {
+ String facetName = in.readUTF();
+ TreeStrutureNode facet = new TreeStrutureNode();
+ facet.readExternal(in);
+ facets.put(facetName, facet);
+ }
+ }
+ int childrenSize = in.readInt();
+ if (childrenSize > 0) {
+ children = new ArrayList(childrenSize);
+ for (int i = 0; i < childrenSize; i++) {
+ TreeStrutureNode child = new TreeStrutureNode();
+ child.readExternal(in);
+ children.add(child);
+ }
+ }
+ }
+
+ public void writeExternal(ObjectOutput out) throws IOException {
+ out.writeUTF(type);
+ out.writeUTF(null == id ? NULL_ID : id);
+ if (null != facets) {
+ out.writeInt(facets.size());
+ for (Iterator i = facets.entrySet().iterator(); i.hasNext();) {
+ Map.Entry entry = (Map.Entry) i.next();
+ out.writeUTF((String) entry.getKey());
+ TreeStrutureNode node = (TreeStrutureNode) entry.getValue();
+ node.writeExternal(out);
+ }
+
+ } else {
+ out.writeInt(0);
+ }
+ if (null != children) {
+ out.writeInt(children.size());
+ for (Iterator i = children.iterator(); i.hasNext();) {
+ TreeStrutureNode child = (TreeStrutureNode) i.next();
+ child.writeExternal(out);
+ }
+
+ } else {
+ out.writeInt(0);
+ }
+ }
+}
\ No newline at end of file
Property changes on:
trunk/framework/impl/src/main/java/org/ajax4jsf/application/TreeStrutureNode.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Name: svn:keywords
+ Date Revision Author
Modified:
trunk/framework/test/src/test/java/org/ajax4jsf/application/AjaxStateHolderTest.java
===================================================================
---
trunk/framework/test/src/test/java/org/ajax4jsf/application/AjaxStateHolderTest.java 2007-10-16
21:08:17 UTC (rev 3409)
+++
trunk/framework/test/src/test/java/org/ajax4jsf/application/AjaxStateHolderTest.java 2007-10-16
23:18:22 UTC (rev 3410)
@@ -36,9 +36,9 @@
* Test method for {@link
org.ajax4jsf.application.AjaxStateHolder#getInstance(javax.faces.context.FacesContext)}.
*/
public void testGetInstance() {
- AjaxStateHolder ajaxStateHolder = AjaxStateHolder.getInstance(facesContext);
+ StateHolder ajaxStateHolder = AjaxStateHolder.getInstance(facesContext);
assertNotNull(ajaxStateHolder);
- AjaxStateHolder ajaxStateHolder2 = AjaxStateHolder.getInstance(facesContext);
+ StateHolder ajaxStateHolder2 = AjaxStateHolder.getInstance(facesContext);
assertSame(ajaxStateHolder, ajaxStateHolder2);
}
@@ -48,7 +48,7 @@
public void testGetState() {
Object state = new Object();
Object state2 = new Object();
- AjaxStateHolder ajaxStateHolder = AjaxStateHolder.getInstance(facesContext);
+ StateHolder ajaxStateHolder = AjaxStateHolder.getInstance(facesContext);
assertNull(ajaxStateHolder.getState("foo", "_id1"));
ajaxStateHolder.saveState("foo", "_id1", state);
ajaxStateHolder.saveState("foo", "_id2", state2);
Modified:
trunk/framework/test/src/test/java/org/ajax4jsf/application/AjaxStateManagerTest.java
===================================================================
---
trunk/framework/test/src/test/java/org/ajax4jsf/application/AjaxStateManagerTest.java 2007-10-16
21:08:17 UTC (rev 3409)
+++
trunk/framework/test/src/test/java/org/ajax4jsf/application/AjaxStateManagerTest.java 2007-10-16
23:18:22 UTC (rev 3410)
@@ -5,22 +5,28 @@
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
+import java.io.IOException;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.util.HashSet;
+import javax.faces.FactoryFinder;
import javax.faces.application.StateManager;
+import javax.faces.application.ViewHandler;
+import javax.faces.application.StateManager.SerializedView;
import javax.faces.component.UIColumn;
import javax.faces.component.UIComponent;
import javax.faces.component.UIData;
import javax.faces.component.UIInput;
import javax.faces.component.UIOutput;
import javax.faces.component.UIViewRoot;
+import javax.faces.context.FacesContext;
import javax.faces.render.RenderKit;
import javax.faces.render.RenderKitFactory;
+import javax.faces.render.ResponseStateManager;
-import org.ajax4jsf.application.AjaxStateManager.TreeStrutureNode;
import org.ajax4jsf.tests.AbstractAjax4JsfTestCase;
+import org.apache.shale.test.mock.MockRenderKit;
/**
@@ -31,7 +37,12 @@
private static final String FACET_B = "facetB";
private static final String FACET_A = "facetA";
+ private static final String AJAX_RENDER_KIT = "AJAX";
+ private AjaxStateManager ajaxStateManager;
+
+ private Object treeStructure;
+ private Object state;
/**
* @param name
*/
@@ -44,6 +55,34 @@
*/
public void setUp() throws Exception {
super.setUp();
+ RenderKitFactory renderKitFactory = (RenderKitFactory)
+ FactoryFinder.getFactory(FactoryFinder.RENDER_KIT_FACTORY);
+ renderKit = new MockRenderKit(){
+ public ResponseStateManager getResponseStateManager() {
+ return new ResponseStateManager(){
+
+ public Object getComponentStateToRestore(FacesContext arg0) {
+ return state;
+ }
+
+ public Object getTreeStructureToRestore(FacesContext arg0,
+ String arg1) {
+ return treeStructure;
+ }
+
+ public void writeState(FacesContext context,
+ SerializedView serializedView) throws IOException {
+ treeStructure = serializedView.getStructure();
+ state = serializedView.getState();
+ }
+
+ };
+ }
+ };
+ renderKitFactory.addRenderKit(AJAX_RENDER_KIT, renderKit);
+ facesContext.getViewRoot().setRenderKitId(AJAX_RENDER_KIT);
+ ajaxStateManager = new AjaxStateManager(application.getStateManager());
+ application.setStateManager(ajaxStateManager);
}
/* (non-Javadoc)
@@ -51,35 +90,44 @@
*/
public void tearDown() throws Exception {
super.tearDown();
+ ajaxStateManager = null;
+ treeStructure = null;
+ state = null;
}
/**
* Test method for {@link
org.ajax4jsf.application.AjaxStateManager#restoreStateFromSession(javax.faces.context.FacesContext,
java.lang.String, java.lang.String)}.
*/
- public void testRestoreStateFromSession() {
-// fail("Not yet implemented");
+ public void testRestoreStateFromSession() {
+ Object structure = new Object();
+ Object treeState = new Object();
+ ajaxStateManager.saveStateInSession(facesContext, structure, treeState);
+ treeStructure = UIViewRoot.UNIQUE_ID_PREFIX+"1";
+ Object[] stateFromSession = ajaxStateManager.restoreStateFromSession(facesContext,
facesContext.getViewRoot().getViewId(), AJAX_RENDER_KIT);
+ assertSame(structure, stateFromSession[0]);
+ assertSame(treeState, stateFromSession[1]);
}
/**
- * Test method for {@link
org.ajax4jsf.application.AjaxStateManager#getNextViewId(javax.faces.context.FacesContext)}.
+ * Test method for {@link
org.ajax4jsf.application.AjaxStateManager#getLogicalViewId(javax.faces.context.FacesContext)}.
*/
public void testGetNextViewId() {
-// fail("Not yet implemented");
+ Object nextViewId = ajaxStateManager.getLogicalViewId(facesContext);
+ Object expected = ajaxStateManager.getLogicalViewId(facesContext);
+ assertFalse(expected.equals(nextViewId));
+ ajaxContext.setAjaxRequest(true);
+ request.setAttribute(AjaxStateManager.VIEW_SEQUENCE, expected);
+ nextViewId = ajaxStateManager.getLogicalViewId(facesContext);
+ assertEquals(expected, nextViewId);
}
- /**
- * Test method for {@link
org.ajax4jsf.application.AjaxStateManager#getNumberOfViews(javax.faces.context.ExternalContext)}.
- */
- public void testGetNumberOfViews() {
-// fail("Not yet implemented");
- }
/**
* Test method for {@link
org.ajax4jsf.application.AjaxStateManager#getRenderKit(javax.faces.context.FacesContext,
java.lang.String)}.
*/
public void testGetRenderKit() {
AjaxStateManager stateManager = getAjaxStateManager();
- RenderKit kit = stateManager.getRenderKit(facesContext,
RenderKitFactory.HTML_BASIC_RENDER_KIT);
+ RenderKit kit = stateManager.getRenderKit(facesContext, AJAX_RENDER_KIT);
assertSame(renderKit, kit);
}
@@ -144,10 +192,8 @@
/**
* @return
*/
- private AjaxStateManager getAjaxStateManager() {
- StateManager defaultStateManager = application.getStateManager();
- AjaxStateManager stateManager = new AjaxStateManager(defaultStateManager);
- return stateManager;
+ private AjaxStateManager getAjaxStateManager() {
+ return ajaxStateManager;
}
}
Modified: trunk/samples/pom.xml
===================================================================
--- trunk/samples/pom.xml 2007-10-16 21:08:17 UTC (rev 3409)
+++ trunk/samples/pom.xml 2007-10-16 23:18:22 UTC (rev 3410)
@@ -443,9 +443,7 @@
<module>calendar-sample</module>
<module>treeModelDemo</module>
<module>local-value-demo</module>
- <!--
- <module>ajaxPortlet</module>
- -->
+ <module>ajaxPortlet</module>
<module>panelmenu-sample</module>
<module>rich-message-demo</module>
<!--
Added: trunk/ui/inputnumber-spinner/src/main/config/resources/resources-config.xml
===================================================================
--- trunk/ui/inputnumber-spinner/src/main/config/resources/resources-config.xml
(rev 0)
+++ trunk/ui/inputnumber-spinner/src/main/config/resources/resources-config.xml 2007-10-16
23:18:22 UTC (rev 3410)
@@ -0,0 +1,12 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<resource-config>
+ <resource
class="org.richfaces.renderkit.html.images.background.SpinnerButtonGradient">
+ <name>org.richfaces.renderkit.html.images.background.SpinnerButtonGradient</name>
+ </resource>
+ <resource
class="org.richfaces.renderkit.html.images.background.SpinnerFieldGradient">
+ <name>org.richfaces.renderkit.html.images.background.SpinnerFieldGradient</name>
+ </resource>
+ <resource
class="org.richfaces.renderkit.html.images.buttons.SpinnerButtonImage">
+ <name>org.richfaces.renderkit.html.images.buttons.SpinnerButtonImage</name>
+ </resource>
+</resource-config>
Property changes on:
trunk/ui/inputnumber-spinner/src/main/config/resources/resources-config.xml
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Name: svn:keywords
+ Date Revision Author
Modified:
trunk/ui/paint2D/src/main/java/org/richfaces/renderkit/html/Paint2DResource.java
===================================================================
---
trunk/ui/paint2D/src/main/java/org/richfaces/renderkit/html/Paint2DResource.java 2007-10-16
21:08:17 UTC (rev 3409)
+++
trunk/ui/paint2D/src/main/java/org/richfaces/renderkit/html/Paint2DResource.java 2007-10-16
23:18:22 UTC (rev 3410)
@@ -66,7 +66,7 @@
public ResourceRenderer getRenderer(ResourceContext context) {
ImageData data = (ImageData) restoreData(context);
- ImageRenderer renderer = _renderers[data._format];
+ ImageRenderer renderer = _renderers[null==data?0:data._format];
return renderer;
}
/* (non-Javadoc)