You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@myfaces.apache.org by lu...@apache.org on 2013/08/12 03:14:14 UTC
svn commit: r1513023 - in
/myfaces/core/trunk/impl/src/main/java/org/apache/myfaces:
cdi/impl/CDIManagedBeanHandlerImpl.java cdi/view/ViewScopeBeanHolder.java
cdi/view/ViewScopeContextImpl.java flow/cdi/FlowScopeBeanHolder.java
Author: lu4242
Date: Mon Aug 12 01:14:14 2013
New Revision: 1513023
URL: http://svn.apache.org/r1513023
Log:
MYFACES-3741 Implement CDI Flow Scope and MYFACES-3747 Implement new JSF 2.2 ViewScope specification (New javadoc in javax.faces.view.ViewScoped enforce FacesContext should be available when @PreDestroy is processed. Use @PreDestroy over a session scope bean will not fit)
Modified:
myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/cdi/impl/CDIManagedBeanHandlerImpl.java
myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/cdi/view/ViewScopeBeanHolder.java
myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/cdi/view/ViewScopeContextImpl.java
myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/flow/cdi/FlowScopeBeanHolder.java
Modified: myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/cdi/impl/CDIManagedBeanHandlerImpl.java
URL: http://svn.apache.org/viewvc/myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/cdi/impl/CDIManagedBeanHandlerImpl.java?rev=1513023&r1=1513022&r2=1513023&view=diff
==============================================================================
--- myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/cdi/impl/CDIManagedBeanHandlerImpl.java (original)
+++ myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/cdi/impl/CDIManagedBeanHandlerImpl.java Mon Aug 12 01:14:14 2013
@@ -26,6 +26,7 @@ import org.apache.myfaces.cdi.util.BeanP
import org.apache.myfaces.cdi.util.CDIUtils;
import org.apache.myfaces.cdi.view.ViewScopeBeanHolder;
import org.apache.myfaces.cdi.view.ViewScopeCDIMap;
+import org.apache.myfaces.flow.cdi.FlowScopeBeanHolder;
/**
*
@@ -38,6 +39,8 @@ public class CDIManagedBeanHandlerImpl e
private ViewScopeBeanHolder viewScopeBeanHolder;
+ private FlowScopeBeanHolder flowScopeBeanHolder;
+
public CDIManagedBeanHandlerImpl()
{
beanManager = CDIUtils.getBeanManager(
@@ -54,6 +57,16 @@ public class CDIManagedBeanHandlerImpl e
return viewScopeBeanHolder;
}
+ private FlowScopeBeanHolder getFlowScopeBeanHolder()
+ {
+ if (flowScopeBeanHolder == null)
+ {
+ flowScopeBeanHolder = BeanProvider.getContextualReference(
+ beanManager, FlowScopeBeanHolder.class, false);
+ }
+ return flowScopeBeanHolder;
+ }
+
public Map<String, Object> createViewScopeMap(FacesContext facesContext, String viewScopeId)
{
return new ViewScopeCDIMap(facesContext, viewScopeId);
@@ -80,5 +93,17 @@ public class CDIManagedBeanHandlerImpl e
// to do anything else in this location, but it is advised
// in CDI the beans are destroyed at the end of the request,
// not when invalidateSession() is called.
+ FacesContext facesContext = FacesContext.getCurrentInstance();
+ if (facesContext != null)
+ {
+ if (ViewScopeBeanHolder.isViewScopeBeanHolderCreated(facesContext))
+ {
+ getViewScopeBeanHolder().destroyBeans();
+ }
+ if (FlowScopeBeanHolder.isFlowScopeBeanHolderCreated(facesContext))
+ {
+ getFlowScopeBeanHolder().destroyBeans();
+ }
+ }
}
}
Modified: myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/cdi/view/ViewScopeBeanHolder.java
URL: http://svn.apache.org/viewvc/myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/cdi/view/ViewScopeBeanHolder.java?rev=1513023&r1=1513022&r2=1513023&view=diff
==============================================================================
--- myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/cdi/view/ViewScopeBeanHolder.java (original)
+++ myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/cdi/view/ViewScopeBeanHolder.java Mon Aug 12 01:14:14 2013
@@ -22,9 +22,10 @@ import java.io.Serializable;
import java.util.Map;
import java.util.Random;
import java.util.concurrent.ConcurrentHashMap;
-import javax.annotation.PreDestroy;
+import javax.annotation.PostConstruct;
import javax.enterprise.context.SessionScoped;
import javax.enterprise.inject.spi.BeanManager;
+import javax.faces.context.FacesContext;
/**
*
@@ -43,10 +44,28 @@ public class ViewScopeBeanHolder impleme
private static final Random RANDOM_GENERATOR = new Random();
+ private static final String VIEW_SCOPE_PREFIX = "oam.view.SCOPE";
+
+ public static final String VIEW_SCOPE_PREFIX_KEY = VIEW_SCOPE_PREFIX+".KEY";
+
public ViewScopeBeanHolder()
{
}
+ @PostConstruct
+ public void init()
+ {
+ FacesContext facesContext = FacesContext.getCurrentInstance();
+ facesContext.getExternalContext().getSessionMap().put(VIEW_SCOPE_PREFIX_KEY,
+ 1);
+ }
+
+ public static final boolean isViewScopeBeanHolderCreated(FacesContext facesContext)
+ {
+ return facesContext.getExternalContext().
+ getSessionMap().containsKey(VIEW_SCOPE_PREFIX_KEY);
+ }
+
/**
* This method will return the ViewScopeContextualStorage or create a new one
* if no one is yet assigned to the current windowId.
@@ -101,7 +120,7 @@ public class ViewScopeBeanHolder impleme
* but can also get invoked manually, e.g. if a user likes to get rid
* of all it's @ViewScoped beans.
*/
- @PreDestroy
+ //@PreDestroy
public void destroyBeans()
{
// we replace the old windowBeanHolder beans with a new storage Map
@@ -110,7 +129,7 @@ public class ViewScopeBeanHolder impleme
for (ViewScopeContextualStorage contextualStorage : oldWindowContextStorages.values())
{
- ViewScopeContextImpl.destroyAllActiveSessionDestroyed(contextualStorage);
+ ViewScopeContextImpl.destroyAllActive(contextualStorage);
}
}
Modified: myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/cdi/view/ViewScopeContextImpl.java
URL: http://svn.apache.org/viewvc/myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/cdi/view/ViewScopeContextImpl.java?rev=1513023&r1=1513022&r2=1513023&view=diff
==============================================================================
--- myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/cdi/view/ViewScopeContextImpl.java (original)
+++ myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/cdi/view/ViewScopeContextImpl.java Mon Aug 12 01:14:14 2013
@@ -213,6 +213,7 @@ public class ViewScopeContextImpl implem
* This is a static method to allow various holder objects to cleanup
* properly in @PreDestroy.
*/
+ /*
public static void destroyAllActive(ViewScopeContextualStorage storage)
{
Map<String, Object> nameBeanKeyMap = storage.getNameBeanKeyMap();
@@ -243,9 +244,9 @@ public class ViewScopeContextImpl implem
}
}
contextMap.clear();
- }
+ }*/
- public static void destroyAllActiveSessionDestroyed(ViewScopeContextualStorage storage)
+ public static void destroyAllActive(ViewScopeContextualStorage storage)
{
Map<String, Object> nameBeanKeyMap = storage.getNameBeanKeyMap();
Map<Object, ContextualInstanceInfo<?>> contextMap = storage.getStorage();
Modified: myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/flow/cdi/FlowScopeBeanHolder.java
URL: http://svn.apache.org/viewvc/myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/flow/cdi/FlowScopeBeanHolder.java?rev=1513023&r1=1513022&r2=1513023&view=diff
==============================================================================
--- myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/flow/cdi/FlowScopeBeanHolder.java (original)
+++ myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/flow/cdi/FlowScopeBeanHolder.java Mon Aug 12 01:14:14 2013
@@ -25,7 +25,7 @@ import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
-import javax.annotation.PreDestroy;
+import javax.annotation.PostConstruct;
import javax.enterprise.context.SessionScoped;
import javax.enterprise.inject.spi.BeanManager;
import javax.faces.context.FacesContext;
@@ -57,11 +57,29 @@ public class FlowScopeBeanHolder impleme
private Map<String, List<String>> activeFlowMapKeys = new ConcurrentHashMap<String, List<String>>();
public static final String CURRENT_FLOW_SCOPE_MAP = "oam.CURRENT_FLOW_SCOPE_MAP";
+
+ private static final String FLOW_SCOPE_PREFIX = "oam.flow.SCOPE";
+
+ public static final String FLOW_SCOPE_PREFIX_KEY = FLOW_SCOPE_PREFIX+".KEY";
public FlowScopeBeanHolder()
{
}
-
+
+ @PostConstruct
+ public void init()
+ {
+ FacesContext facesContext = FacesContext.getCurrentInstance();
+ facesContext.getExternalContext().getSessionMap().put(FLOW_SCOPE_PREFIX_KEY,
+ 1);
+ }
+
+ public static final boolean isFlowScopeBeanHolderCreated(FacesContext facesContext)
+ {
+ return facesContext.getExternalContext().
+ getSessionMap().containsKey(FLOW_SCOPE_PREFIX_KEY);
+ }
+
/**
* This method will return the ContextualStorage or create a new one
* if no one is yet assigned to the current flowClientWindowId.
@@ -157,7 +175,7 @@ public class FlowScopeBeanHolder impleme
* but can also get invoked manually, e.g. if a user likes to get rid
* of all it's @WindowScoped beans.
*/
- @PreDestroy
+ //@PreDestroy
public void destroyBeans()
{
// we replace the old windowBeanHolder beans with a new storage Map