You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@myfaces.apache.org by ja...@apache.org on 2010/10/28 11:36:02 UTC
svn commit: r1028246 -
/myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/el/FlashELResolver.java
Author: jakobk
Date: Thu Oct 28 09:36:01 2010
New Revision: 1028246
URL: http://svn.apache.org/viewvc?rev=1028246&view=rev
Log:
MYFACES-2942 Memory Leak in MyFaces 2.0.1 probably as well in 2.0.2 (re-applying changes on FacesElResolver as discussed)
Modified:
myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/el/FlashELResolver.java
Modified: myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/el/FlashELResolver.java
URL: http://svn.apache.org/viewvc/myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/el/FlashELResolver.java?rev=1028246&r1=1028245&r2=1028246&view=diff
==============================================================================
--- myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/el/FlashELResolver.java (original)
+++ myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/el/FlashELResolver.java Thu Oct 28 09:36:01 2010
@@ -18,10 +18,6 @@
*/
package org.apache.myfaces.el;
-import java.beans.FeatureDescriptor;
-import java.util.ArrayList;
-import java.util.Iterator;
-
import javax.el.ELContext;
import javax.el.ELException;
import javax.el.ELResolver;
@@ -30,6 +26,9 @@ import javax.el.PropertyNotWritableExcep
import javax.faces.context.ExternalContext;
import javax.faces.context.FacesContext;
import javax.faces.context.Flash;
+import java.beans.FeatureDescriptor;
+import java.util.ArrayList;
+import java.util.Iterator;
/**
* Resolver for Flash object
@@ -118,16 +117,19 @@ public class FlashELResolver extends ELR
String strProperty = castAndIntern(property);
+ FacesContext facesContext = facesContext(elContext);
+ ExternalContext externalContext = facesContext.getExternalContext();
+
if (base == null)
{
if (FLASH.equals(strProperty))
{
//Access to flash object
elContext.setPropertyResolved(true);
- Flash flash = externalContext(elContext).getFlash();
+ Flash flash = externalContext.getFlash();
//This is just to make sure after this point
//we are not in "keep" promotion.
- setDoKeepPromotion(false);
+ setDoKeepPromotion(false, facesContext);
// Note that after this object is returned, Flash.get() and Flash.put()
// methods are called from javax.el.MapELResolver, since
@@ -140,7 +142,7 @@ public class FlashELResolver extends ELR
Flash flash = (Flash) base;
if (KEEP.equals(strProperty))
{
- setDoKeepPromotion(true);
+ setDoKeepPromotion(true, facesContext);
// Since we returned a Flash instance getValue will
// be called again but this time the property name
// to be resolved will be called, so we can do keep
@@ -150,22 +152,22 @@ public class FlashELResolver extends ELR
else if (NOW.equals(strProperty))
{
//Prevent invalid syntax #{flash.keep.now.someKey}
- if (!isDoKeepPromotion())
+ if (!isDoKeepPromotion(facesContext))
{
// According to the javadoc of Flash.putNow() and
// Flash.keep(), this is an alias to requestMap, used
// as a "buffer" to promote vars to flash scope using
// "keep" method
elContext.setPropertyResolved(true);
- return externalContext(elContext).getRequestMap();
+ return externalContext.getRequestMap();
}
}
- else if (isDoKeepPromotion())
+ else if (isDoKeepPromotion(facesContext))
{
//Resolve property calling get or keep
elContext.setPropertyResolved(true);
//Obtain the value on requestMap if any
- Object value = externalContext(elContext).getRequestMap().get(strProperty);
+ Object value = externalContext.getRequestMap().get(strProperty);
//promote it to flash scope
flash.keep(strProperty);
return value;
@@ -194,24 +196,23 @@ public class FlashELResolver extends ELR
*
* This var do the job.
*/
- private static ThreadLocal<Boolean> _keepStatus =
- new ThreadLocal<Boolean>()
- {
- @Override
- protected Boolean initialValue()
- {
- return Boolean.FALSE;
- }
- };
+ private static final String KEEP_STATUS_KEY = "org.apache.myfaces.el.FlashELResolver.KEEP_STATUS";
- private static boolean isDoKeepPromotion()
+ private static boolean isDoKeepPromotion(FacesContext facesContext)
{
- return _keepStatus.get();
+ Boolean doKeepPromotion = (Boolean) facesContext.getAttributes().get(KEEP_STATUS_KEY);
+
+ if (doKeepPromotion == null)
+ {
+ doKeepPromotion = false;
+ }
+
+ return doKeepPromotion;
}
- private static void setDoKeepPromotion(boolean value)
+ private static void setDoKeepPromotion(boolean value, FacesContext facesContext)
{
- _keepStatus.set(Boolean.valueOf(value));
+ facesContext.getAttributes().put(KEEP_STATUS_KEY, Boolean.valueOf(value));
}
// get the FacesContext from the ELContext