Author: alexsmirnov
Date: 2008-04-28 18:19:49 -0400 (Mon, 28 Apr 2008)
New Revision: 8270
Modified:
trunk/framework/api/src/main/java/org/ajax4jsf/application/StateHolder.java
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/ui/dataTable/src/main/java/org/richfaces/component/UIDataGrid.java
Log:
fix
http://jira.jboss.com/jira/browse/RF-1924 ,
http://jira.jboss.com/jira/browse/RF-2076
Modified: trunk/framework/api/src/main/java/org/ajax4jsf/application/StateHolder.java
===================================================================
--- trunk/framework/api/src/main/java/org/ajax4jsf/application/StateHolder.java 2008-04-28
21:02:55 UTC (rev 8269)
+++ trunk/framework/api/src/main/java/org/ajax4jsf/application/StateHolder.java 2008-04-28
22:19:49 UTC (rev 8270)
@@ -2,8 +2,8 @@
public interface StateHolder {
- public Object getState(String viewId, Object sequence);
+ public Object getState(String viewId, String sequence);
- public void saveState(String viewId, Object sequence, Object state);
+ public void saveState(String viewId, String sequence, Object state);
}
\ No newline at end of file
Modified:
trunk/framework/impl/src/main/java/org/ajax4jsf/application/AjaxStateHolder.java
===================================================================
---
trunk/framework/impl/src/main/java/org/ajax4jsf/application/AjaxStateHolder.java 2008-04-28
21:02:55 UTC (rev 8269)
+++
trunk/framework/impl/src/main/java/org/ajax4jsf/application/AjaxStateHolder.java 2008-04-28
22:19:49 UTC (rev 8270)
@@ -24,15 +24,15 @@
/**
*
*/
- private static final long serialVersionUID = 6414488517358423688L;
- private static final Object STATE_HOLDER = AjaxStateHolder.class.getName();
+ private static final long serialVersionUID = 6414488517358423537L;
+ private static final String STATE_HOLDER = AjaxStateHolder.class.getName();
- private final LRUMap views;
+ private final LRUMap<String,LRUMap<String, Object>> views;
private final int numberOfViews;
private AjaxStateHolder(int capacity, int numberOfViews) {
- views = new LRUMap(capacity);
+ views = new LRUMap<String,LRUMap<String, Object>>(capacity);
this.numberOfViews = numberOfViews;
}
@@ -43,7 +43,7 @@
}
ExternalContext externalContext = context.getExternalContext();
Object session = externalContext.getSession(true);
- Map sessionMap = externalContext.getSessionMap();
+ Map<String,Object> sessionMap = externalContext.getSessionMap();
if (_log.isDebugEnabled()) {
_log.debug("Request for a view states holder instance");
}
@@ -75,14 +75,14 @@
/* (non-Javadoc)
* @see org.ajax4jsf.application.StateHolder#getState(java.lang.String,
java.lang.Object)
*/
- public Object getState(String viewId, Object sequence) {
+ public Object getState(String viewId, String sequence) {
if (null == viewId) {
throw new NullPointerException(
"viewId parameter for get saved view state is null");
}
Object state = null;
synchronized (views) {
- LRUMap viewVersions = (LRUMap) views.get(viewId);
+ LRUMap<String,Object> viewVersions = views.get(viewId);
if (null != viewVersions) {
if (null != sequence) {
state = viewVersions.get(sequence);
@@ -103,7 +103,7 @@
/* (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) {
+ public void saveState(String viewId, String sequence, Object state) {
if (null == viewId) {
throw new NullPointerException(
"viewId parameter for save view state is null");
@@ -117,10 +117,10 @@
_log.debug("Save new viewState in session for viewId "+viewId+" and
sequence "+sequence);
}
synchronized (views) {
- LRUMap viewVersions = (LRUMap) views.get(viewId);
+ LRUMap<String,Object> viewVersions = views.get(viewId);
if (null == viewVersions) {
// TODO - make size parameter configurable
- viewVersions = new LRUMap(this.numberOfViews);
+ viewVersions = new LRUMap<String,Object>(this.numberOfViews);
views.put(viewId, viewVersions);
}
viewVersions.put(sequence, state);
Modified:
trunk/framework/impl/src/main/java/org/ajax4jsf/application/AjaxStateManager.java
===================================================================
---
trunk/framework/impl/src/main/java/org/ajax4jsf/application/AjaxStateManager.java 2008-04-28
21:02:55 UTC (rev 8269)
+++
trunk/framework/impl/src/main/java/org/ajax4jsf/application/AjaxStateManager.java 2008-04-28
22:19:49 UTC (rev 8270)
@@ -24,10 +24,12 @@
import java.io.IOException;
import java.lang.reflect.Constructor;
import java.util.HashSet;
+import java.util.Map;
import javax.faces.FactoryFinder;
import javax.faces.application.StateManager;
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;
@@ -101,12 +103,10 @@
private final ComponentsLoader componentLoader;
- private volatile int viewSequence = 0;
+ private static final Log _log = LogFactory.getLog(AjaxStateManager.class);
- private Object viewSequenceMutex = "MUTEX";
+ public static final String VIEW_SEQUENCE_ATTRIBUTE =
AjaxStateManager.class.getName()+".view_sequence";
- private static final Log _log = LogFactory.getLog(AjaxStateManager.class);
-
/**
* @param parent
*/
@@ -242,7 +242,7 @@
protected Object[] restoreStateFromSession(FacesContext context,
String viewId, String renderKitId) {
- Object id = restoreLogicalViewId(context, viewId, renderKitId);
+ String id = restoreLogicalViewId(context, viewId, renderKitId);
StateHolder stateHolder = getStateHolder(context);
Object[] restoredState = (Object[]) stateHolder.getState(viewId, id);
return restoredState;
@@ -292,7 +292,7 @@
SerializedView serializedView;
UIViewRoot viewRoot = context.getViewRoot();
StateHolder stateHolder = getStateHolder(context);
- Object id = getLogicalViewId(context);
+ String id = getLogicalViewId(context);
stateHolder.saveState(viewRoot.getViewId(), id, new Object[] {
treeStructure, state });
serializedView = new SerializedView(id, null);
@@ -323,9 +323,9 @@
* @return
*/
@SuppressWarnings("deprecation")
- protected Object restoreLogicalViewId(FacesContext context, String viewId,
+ protected String restoreLogicalViewId(FacesContext context, String viewId,
String renderKitId) {
- Object id = getRenderKit(context, renderKitId)
+ String id = (String) getRenderKit(context, renderKitId)
.getResponseStateManager().getTreeStructureToRestore(context,
viewId);
if (null != id) {
@@ -340,19 +340,32 @@
* @param context
* @return
*/
- protected Object getLogicalViewId(FacesContext context) {
+ protected String getLogicalViewId(FacesContext context) {
AjaxContext ajaxContext = AjaxContext.getCurrentInstance(context);
+ ExternalContext externalContext = context.getExternalContext();
if (ajaxContext.isAjaxRequest()) {
- Object id = context.getExternalContext().getRequestMap().get(
+ Object id = externalContext.getRequestMap().get(
VIEW_SEQUENCE);
if (null != id) {
- return id;
+ return id.toString();
}
}
- synchronized (viewSequenceMutex) {
+ // Store sequence in session, to avoyd claster configuration problem
+ // see
https://javaserverfaces.dev.java.net/issues/show_bug.cgi?id=662
+ Object session = externalContext.getSession(true);
+ int viewSequence;
+ synchronized (session) {
+ Map<String, Object> sessionMap = externalContext.getSessionMap();
+ Integer sequence = (Integer) sessionMap.get(VIEW_SEQUENCE_ATTRIBUTE);
+ if(null != sequence){
+ viewSequence = sequence.intValue();
+ } else {
+ viewSequence = 0;
+ }
if (viewSequence++ == Character.MAX_VALUE) {
viewSequence = 0;
}
+ sessionMap.put(VIEW_SEQUENCE_ATTRIBUTE, new Integer(viewSequence));
}
return UIViewRoot.UNIQUE_ID_PREFIX + ((int) viewSequence);
}
Modified:
trunk/framework/test/src/test/java/org/ajax4jsf/application/AjaxStateHolderTest.java
===================================================================
---
trunk/framework/test/src/test/java/org/ajax4jsf/application/AjaxStateHolderTest.java 2008-04-28
21:02:55 UTC (rev 8269)
+++
trunk/framework/test/src/test/java/org/ajax4jsf/application/AjaxStateHolderTest.java 2008-04-28
22:19:49 UTC (rev 8270)
@@ -43,7 +43,7 @@
}
/**
- * Test method for {@link
org.ajax4jsf.application.AjaxStateHolder#getState(java.lang.String, java.lang.Object)}.
+ * Test method for {@link
org.ajax4jsf.application.AjaxStateHolder#getState(java.lang.String, String)}.
*/
public void testGetState() {
Object state = new Object();
Modified: trunk/ui/dataTable/src/main/java/org/richfaces/component/UIDataGrid.java
===================================================================
--- trunk/ui/dataTable/src/main/java/org/richfaces/component/UIDataGrid.java 2008-04-28
21:02:55 UTC (rev 8269)
+++ trunk/ui/dataTable/src/main/java/org/richfaces/component/UIDataGrid.java 2008-04-28
22:19:49 UTC (rev 8270)
@@ -60,7 +60,6 @@
* @see org.ajax4jsf.ajax.repeat.UIDataAdaptor#dataChildren()
*/
protected Iterator<UIComponent> dataChildren() {
- // TODO Auto-generated method stub
return getChildren().iterator();
}
@@ -68,7 +67,6 @@
* @see org.ajax4jsf.ajax.repeat.UIDataAdaptor#fixedChildren()
*/
protected Iterator<UIComponent> fixedChildren() {
- // TODO Auto-generated method stub
return getFacets().values().iterator();
}