myfaces-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From gpetra...@apache.org
Subject svn commit: r1071155 - in /myfaces/extensions/cdi/trunk: core/api/src/main/java/org/apache/myfaces/extensions/cdi/core/api/scope/conversation/config/ jee-modules/jsf-module/impl/src/main/java/org/apache/myfaces/extensions/cdi/jsf/impl/scope/conversatio...
Date Wed, 16 Feb 2011 06:41:28 GMT
Author: gpetracek
Date: Wed Feb 16 06:41:27 2011
New Revision: 1071155

URL: http://svn.apache.org/viewvc?rev=1071155&view=rev
Log:
EXTCDI-137 first draft of eager window-id detection

Modified:
    myfaces/extensions/cdi/trunk/core/api/src/main/java/org/apache/myfaces/extensions/cdi/core/api/scope/conversation/config/WindowContextConfig.java
    myfaces/extensions/cdi/trunk/jee-modules/jsf-module/impl/src/main/java/org/apache/myfaces/extensions/cdi/jsf/impl/scope/conversation/DefaultWindowContextManager.java
    myfaces/extensions/cdi/trunk/jee-modules/jsf-module/impl/src/main/java/org/apache/myfaces/extensions/cdi/jsf/impl/scope/conversation/EditableWindowContextManagerProxy.java
    myfaces/extensions/cdi/trunk/jee-modules/jsf-module/impl/src/main/java/org/apache/myfaces/extensions/cdi/jsf/impl/scope/conversation/WindowContextManagerObserver.java
    myfaces/extensions/cdi/trunk/jee-modules/jsf-module/impl/src/main/java/org/apache/myfaces/extensions/cdi/jsf/impl/scope/conversation/spi/EditableWindowContextManager.java

Modified: myfaces/extensions/cdi/trunk/core/api/src/main/java/org/apache/myfaces/extensions/cdi/core/api/scope/conversation/config/WindowContextConfig.java
URL: http://svn.apache.org/viewvc/myfaces/extensions/cdi/trunk/core/api/src/main/java/org/apache/myfaces/extensions/cdi/core/api/scope/conversation/config/WindowContextConfig.java?rev=1071155&r1=1071154&r2=1071155&view=diff
==============================================================================
--- myfaces/extensions/cdi/trunk/core/api/src/main/java/org/apache/myfaces/extensions/cdi/core/api/scope/conversation/config/WindowContextConfig.java
(original)
+++ myfaces/extensions/cdi/trunk/core/api/src/main/java/org/apache/myfaces/extensions/cdi/core/api/scope/conversation/config/WindowContextConfig.java
Wed Feb 16 06:41:27 2011
@@ -103,6 +103,17 @@ public class WindowContextConfig extends
         return false;
     }
 
+    /**
+     * Allows to restore the window-context before the component tree gets built.
+     * Per default it's only supported if {#isUrlParameterSupported} is true as well.
+     * 
+     * @return true for activating it, false otherwise
+     */
+    public boolean isEagerWindowContextDetectionEnabled()
+    {
+        return isUrlParameterSupported();
+    }
+
     /*
      * event config
      */

Modified: myfaces/extensions/cdi/trunk/jee-modules/jsf-module/impl/src/main/java/org/apache/myfaces/extensions/cdi/jsf/impl/scope/conversation/DefaultWindowContextManager.java
URL: http://svn.apache.org/viewvc/myfaces/extensions/cdi/trunk/jee-modules/jsf-module/impl/src/main/java/org/apache/myfaces/extensions/cdi/jsf/impl/scope/conversation/DefaultWindowContextManager.java?rev=1071155&r1=1071154&r2=1071155&view=diff
==============================================================================
--- myfaces/extensions/cdi/trunk/jee-modules/jsf-module/impl/src/main/java/org/apache/myfaces/extensions/cdi/jsf/impl/scope/conversation/DefaultWindowContextManager.java
(original)
+++ myfaces/extensions/cdi/trunk/jee-modules/jsf-module/impl/src/main/java/org/apache/myfaces/extensions/cdi/jsf/impl/scope/conversation/DefaultWindowContextManager.java
Wed Feb 16 06:41:27 2011
@@ -362,6 +362,13 @@ public class DefaultWindowContextManager
         }
     }
 
+    public boolean isWindowContextActive(String windowContextId)
+    {
+        EditableWindowContext editableWindowContext = this.windowContextMap.get(windowContextId);
+
+        return editableWindowContext != null && editableWindowContext.isActive();
+    }
+
     private EditableWindowContext convert(WindowContext windowContext)
     {
         if(!(windowContext instanceof EditableWindowContext))

Modified: myfaces/extensions/cdi/trunk/jee-modules/jsf-module/impl/src/main/java/org/apache/myfaces/extensions/cdi/jsf/impl/scope/conversation/EditableWindowContextManagerProxy.java
URL: http://svn.apache.org/viewvc/myfaces/extensions/cdi/trunk/jee-modules/jsf-module/impl/src/main/java/org/apache/myfaces/extensions/cdi/jsf/impl/scope/conversation/EditableWindowContextManagerProxy.java?rev=1071155&r1=1071154&r2=1071155&view=diff
==============================================================================
--- myfaces/extensions/cdi/trunk/jee-modules/jsf-module/impl/src/main/java/org/apache/myfaces/extensions/cdi/jsf/impl/scope/conversation/EditableWindowContextManagerProxy.java
(original)
+++ myfaces/extensions/cdi/trunk/jee-modules/jsf-module/impl/src/main/java/org/apache/myfaces/extensions/cdi/jsf/impl/scope/conversation/EditableWindowContextManagerProxy.java
Wed Feb 16 06:41:27 2011
@@ -152,4 +152,9 @@ public class EditableWindowContextManage
     {
         return editableWindowContextManager.getWindowContext(windowContextId);
     }
+
+    public boolean isWindowContextActive(String windowContextId)
+    {
+        return editableWindowContextManager.isWindowContextActive(windowContextId);
+    }
 }

Modified: myfaces/extensions/cdi/trunk/jee-modules/jsf-module/impl/src/main/java/org/apache/myfaces/extensions/cdi/jsf/impl/scope/conversation/WindowContextManagerObserver.java
URL: http://svn.apache.org/viewvc/myfaces/extensions/cdi/trunk/jee-modules/jsf-module/impl/src/main/java/org/apache/myfaces/extensions/cdi/jsf/impl/scope/conversation/WindowContextManagerObserver.java?rev=1071155&r1=1071154&r2=1071155&view=diff
==============================================================================
--- myfaces/extensions/cdi/trunk/jee-modules/jsf-module/impl/src/main/java/org/apache/myfaces/extensions/cdi/jsf/impl/scope/conversation/WindowContextManagerObserver.java
(original)
+++ myfaces/extensions/cdi/trunk/jee-modules/jsf-module/impl/src/main/java/org/apache/myfaces/extensions/cdi/jsf/impl/scope/conversation/WindowContextManagerObserver.java
Wed Feb 16 06:41:27 2011
@@ -21,6 +21,7 @@ package org.apache.myfaces.extensions.cd
 import org.apache.myfaces.extensions.cdi.core.api.scope.conversation.config.WindowContextConfig;
 import org.apache.myfaces.extensions.cdi.jsf.api.listener.phase.AfterPhase;
 import org.apache.myfaces.extensions.cdi.jsf.api.listener.phase.JsfPhaseId;
+import org.apache.myfaces.extensions.cdi.jsf.api.listener.phase.BeforePhase;
 import org.apache.myfaces.extensions.cdi.jsf.api.request.RequestTypeResolver;
 import org.apache.myfaces.extensions.cdi.jsf.api.config.JsfModuleConfig;
 import org.apache.myfaces.extensions.cdi.jsf.impl.listener.request.FacesMessageEntry;
@@ -29,6 +30,9 @@ import org.apache.myfaces.extensions.cdi
 import org.apache.myfaces.extensions.cdi.jsf.impl.scope.conversation.spi.EditableWindowContextManager;
 import org.apache.myfaces.extensions.cdi.jsf.impl.scope.conversation.spi.WindowHandler;
 import org.apache.myfaces.extensions.cdi.jsf.impl.util.ConversationUtils;
+import org.apache.myfaces.extensions.cdi.jsf.impl.util.RequestCache;
+import static org.apache.myfaces.extensions.cdi.jsf.impl.util.ConversationUtils.*;
+import static org.apache.myfaces.extensions.cdi.jsf.impl.util.ConversationUtils.resolveWindowContextId;
 import org.apache.myfaces.extensions.cdi.message.api.Message;
 
 import javax.enterprise.event.Observes;
@@ -41,10 +45,7 @@ import static org.apache.myfaces.extensi
         .AUTOMATED_ENTRY_POINT_PARAMETER_KEY;
 import static org.apache.myfaces.extensions.cdi.core.impl.scope.conversation.spi.WindowContextManager
         .WINDOW_CONTEXT_ID_PARAMETER_KEY;
-import static org.apache.myfaces.extensions.cdi.jsf.impl.util.ConversationUtils.cleanupInactiveWindowContexts;
-import static org.apache.myfaces.extensions.cdi.jsf.impl.util.ConversationUtils.resolveWindowContextId;
-import static org.apache.myfaces.extensions.cdi.jsf.impl.util.ConversationUtils.storeCurrentViewIdAsNewViewId;
-import static org.apache.myfaces.extensions.cdi.jsf.impl.util.ConversationUtils.storeCurrentViewIdAsOldViewId;
+import org.apache.myfaces.extensions.cdi.core.impl.scope.conversation.spi.WindowContextManager;
 
 /**
  * @author Gerhard Petracek
@@ -52,6 +53,45 @@ import static org.apache.myfaces.extensi
 @SuppressWarnings({"UnusedDeclaration"})
 final class WindowContextManagerObserver
 {
+    /**
+     * tries to restore the window-id and the window-context as early as possible
+     * @param phaseEvent the current jsf phase-event
+     * @param windowContextManager the current window-context-manager
+     * @param windowHandler current window-handler
+     * @param windowContextConfig the active window-context-config
+     */
+    protected void tryToRestoreWindowContext(@Observes @BeforePhase(JsfPhaseId.RESTORE_VIEW)
PhaseEvent phaseEvent,
+                                             EditableWindowContextManager windowContextManager,
+                                             WindowHandler windowHandler,
+                                             WindowContextConfig windowContextConfig)
+    {
+        boolean requestParameterSupported = windowContextConfig.isUrlParameterSupported();
+        if(!(requestParameterSupported && windowContextConfig.isEagerWindowContextDetectionEnabled())
||
+                RequestCache.getCurrentWindowContext() != null /*skip the process if there
is a custom mechanism*/)
+        {
+            return;
+        }
+
+        //don't use: windowContextManager.getCurrentWindowContext(); it would create a new
window-id immediately and
+        //it would break other features.
+        String windowId = resolveWindowContextId(windowHandler,
+                                                 requestParameterSupported,
+                                                 windowContextConfig.isUnknownWindowIdsAllowed());
+
+        if(windowId != null)
+        {
+            boolean active = windowContextManager.isWindowContextActive(windowId);
+
+            if(active)
+            {
+                RequestCache.setCurrentWindowContext(windowContextManager.getWindowContext(windowId));
+                //just for supporting e.g. el-expressions
+                phaseEvent.getFacesContext().getExternalContext().getRequestMap()
+                        .put(WindowContextManager.WINDOW_CONTEXT_ID_PARAMETER_KEY, windowId);
+            }
+        }
+    }
+
     //don't change/optimize this observer!!!
     protected void cleanup(@Observes @AfterPhase(JsfPhaseId.RESTORE_VIEW) PhaseEvent phaseEvent,
                            RequestTypeResolver requestTypeResolver,

Modified: myfaces/extensions/cdi/trunk/jee-modules/jsf-module/impl/src/main/java/org/apache/myfaces/extensions/cdi/jsf/impl/scope/conversation/spi/EditableWindowContextManager.java
URL: http://svn.apache.org/viewvc/myfaces/extensions/cdi/trunk/jee-modules/jsf-module/impl/src/main/java/org/apache/myfaces/extensions/cdi/jsf/impl/scope/conversation/spi/EditableWindowContextManager.java?rev=1071155&r1=1071154&r2=1071155&view=diff
==============================================================================
--- myfaces/extensions/cdi/trunk/jee-modules/jsf-module/impl/src/main/java/org/apache/myfaces/extensions/cdi/jsf/impl/scope/conversation/spi/EditableWindowContextManager.java
(original)
+++ myfaces/extensions/cdi/trunk/jee-modules/jsf-module/impl/src/main/java/org/apache/myfaces/extensions/cdi/jsf/impl/scope/conversation/spi/EditableWindowContextManager.java
Wed Feb 16 06:41:27 2011
@@ -54,4 +54,6 @@ public interface EditableWindowContextMa
     Collection<EditableWindowContext> getWindowContexts();
 
     void closeAllWindowContexts();
+
+    boolean isWindowContextActive(String windowContextId);
 }



Mime
View raw message