You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@myfaces.apache.org by mc...@apache.org on 2010/06/15 17:04:42 UTC
svn commit: r954927 - in /myfaces:
core/trunk/impl/src/main/java/org/apache/myfaces/application/jsp/JspStateManagerImpl.java
shared/trunk/core/src/main/java/org/apache/myfaces/shared/context/flash/FlashImpl.java
Author: mconcini
Date: Tue Jun 15 15:04:41 2010
New Revision: 954927
URL: http://svn.apache.org/viewvc?rev=954927&view=rev
Log:
MYFACES-2754 - MyFaces can attempt to create a new session after the response has been committed
Modified:
myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/application/jsp/JspStateManagerImpl.java
myfaces/shared/trunk/core/src/main/java/org/apache/myfaces/shared/context/flash/FlashImpl.java
Modified: myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/application/jsp/JspStateManagerImpl.java
URL: http://svn.apache.org/viewvc/myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/application/jsp/JspStateManagerImpl.java?rev=954927&r1=954926&r2=954927&view=diff
==============================================================================
--- myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/application/jsp/JspStateManagerImpl.java (original)
+++ myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/application/jsp/JspStateManagerImpl.java Tue Jun 15 15:04:41 2010
@@ -179,8 +179,10 @@ public class JspStateManagerImpl extends
private static final int JSF_SEQUENCE_INDEX = 0;
+ private static final String JSP_IS_WRITING_STATE_ATTR = "org.apache.myfaces.JSP_IS_WRITING_STATE";
+
private RenderKitFactory _renderKitFactory = null;
-
+
public JspStateManagerImpl()
{
if (log.isLoggable(Level.FINEST)) log.finest("New JspStateManagerImpl instance created");
@@ -465,6 +467,11 @@ public class JspStateManagerImpl extends
{
if (log.isLoggable(Level.FINEST)) log.finest("Entering saveSerializedView");
+ if(!isWritingState(facesContext)){
+ if (log.isLoggable(Level.FINEST)) log.finest("Exiting saveSerializedView - no state to save");
+ return null;
+ }
+
checkForDuplicateIds(facesContext, facesContext.getViewRoot(), new HashSet<String>());
if (log.isLoggable(Level.FINEST)) log.finest("Processing saveSerializedView - Checked for duplicate Ids");
@@ -586,7 +593,9 @@ public class JspStateManagerImpl extends
//save state in response (client)
RenderKit renderKit = getRenderKitFactory().getRenderKit(facesContext, uiViewRoot.getRenderKitId());
ResponseStateManager responseStateManager = renderKit.getResponseStateManager();
-
+
+ setWritingState(facesContext);
+
if (isLegacyResponseStateManager(responseStateManager))
{
responseStateManager.writeState(facesContext, serializedView);
@@ -604,7 +613,7 @@ public class JspStateManagerImpl extends
state[1] = serializedView.getState();
responseStateManager.writeState(facesContext, state);
}
-
+
if (log.isLoggable(Level.FINEST)) log.finest("Exiting writeState");
}
@@ -965,6 +974,15 @@ public class JspStateManagerImpl extends
return true;
}
+ private void setWritingState(FacesContext context){
+ context.getAttributes().put(JSP_IS_WRITING_STATE_ATTR, true);
+ }
+
+ private boolean isWritingState(FacesContext context){
+ Boolean writingState = (Boolean)context.getAttributes().get(JSP_IS_WRITING_STATE_ATTR);
+ return writingState == null ? false : writingState;
+ }
+
protected static class SerializedViewCollection implements Serializable
{
private static final long serialVersionUID = -3734849062185115847L;
@@ -1173,4 +1191,4 @@ public class JspStateManagerImpl extends
}
}
-}
+}
\ No newline at end of file
Modified: myfaces/shared/trunk/core/src/main/java/org/apache/myfaces/shared/context/flash/FlashImpl.java
URL: http://svn.apache.org/viewvc/myfaces/shared/trunk/core/src/main/java/org/apache/myfaces/shared/context/flash/FlashImpl.java?rev=954927&r1=954926&r2=954927&view=diff
==============================================================================
--- myfaces/shared/trunk/core/src/main/java/org/apache/myfaces/shared/context/flash/FlashImpl.java (original)
+++ myfaces/shared/trunk/core/src/main/java/org/apache/myfaces/shared/context/flash/FlashImpl.java Tue Jun 15 15:04:41 2010
@@ -169,7 +169,9 @@ public class FlashImpl extends Flash
String token, boolean createIfNeeded)
{
ExternalContext external = context.getExternalContext();
- Object session = external.getSession(true);
+ Object session = external.getSession(createIfNeeded);
+ if (session == null)
+ return null;
Map<String, Object> map = null;
@@ -214,9 +216,14 @@ public class FlashImpl extends Flash
return map;
}
- @SuppressWarnings("unchecked")
protected Map<String, Object> getPostbackRequestMap(FacesContext context)
{
+ return _getPostbackRequestMap(context, true);
+ }
+
+ @SuppressWarnings("unchecked")
+ private Map<String, Object> _getPostbackRequestMap(FacesContext context, boolean createIfNeeded)
+ {
Map<String, Object> requestMap = context.getExternalContext().getRequestMap();
Map<String, Object> map = (Map<String, Object>) requestMap.get(FLASH_POSTBACK_MAP_CACHE);
if (map == null)
@@ -229,7 +236,7 @@ public class FlashImpl extends Flash
token = _getPostbackMapKey(context.getExternalContext());
}
String fullToken = FLASH_SCOPE_CACHE + SEPARATOR_CHAR + token;
- map = _getMapFromSession(context, fullToken, true);
+ map = _getMapFromSession(context, fullToken, createIfNeeded);
requestMap.put(FLASH_POSTBACK_MAP_CACHE, map);
}
return map;
@@ -293,16 +300,19 @@ public class FlashImpl extends Flash
return getPostbackRequestMap(facesContext);
}
}
-
+
private void _removeAllChildren(FacesContext facesContext)
{
- Map<String, Object> map = getPostbackRequestMap(facesContext);
-
+ Map<String, Object> map = _getPostbackRequestMap(facesContext, false);
+
// Clear everything - note that because of naming conventions,
// this will in fact automatically recurse through all children
// grandchildren etc. - which is kind of a design flaw of SubKeyMap,
// but one we're relying on
- map.clear();
+ if (map != null)
+ {
+ map.clear();
+ }
}
/**