deltaspike-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From tandrasc...@apache.org
Subject [2/2] deltaspike git commit: DELTASPIKE-935 ds:disableClientWindow should also disable JSF 2.2 rendering mode
Date Sun, 05 Jul 2015 22:28:02 GMT
DELTASPIKE-935 ds:disableClientWindow should also disable JSF 2.2 rendering mode

Project: http://git-wip-us.apache.org/repos/asf/deltaspike/repo
Commit: http://git-wip-us.apache.org/repos/asf/deltaspike/commit/70c42ca9
Tree: http://git-wip-us.apache.org/repos/asf/deltaspike/tree/70c42ca9
Diff: http://git-wip-us.apache.org/repos/asf/deltaspike/diff/70c42ca9

Branch: refs/heads/master
Commit: 70c42ca9d58cc659d46de2decd871e362c0eed12
Parents: 7139478
Author: Thomas Andraschko <tandraschko@apache.org>
Authored: Mon Jul 6 00:26:56 2015 +0200
Committer: Thomas Andraschko <tandraschko@apache.org>
Committed: Mon Jul 6 00:26:56 2015 +0200

----------------------------------------------------------------------
 .../jsf/api/config/JsfModuleConfig.java         | 76 +++++++++++++-------
 .../window/DisableClientWindowHtmlRenderer.java | 48 +++++++++----
 .../JsfClientWindowAwareLifecycleWrapper.java   |  3 +-
 .../impl/scope/window/ClientWindowAdapter.java  | 39 ++++++++--
 .../strategy/AbstractClientWindowStrategy.java  | 26 +++++++
 .../strategy/DelegatedWindowStrategy.java       | 26 ++-----
 6 files changed, 150 insertions(+), 68 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/deltaspike/blob/70c42ca9/deltaspike/modules/jsf/api/src/main/java/org/apache/deltaspike/jsf/api/config/JsfModuleConfig.java
----------------------------------------------------------------------
diff --git a/deltaspike/modules/jsf/api/src/main/java/org/apache/deltaspike/jsf/api/config/JsfModuleConfig.java
b/deltaspike/modules/jsf/api/src/main/java/org/apache/deltaspike/jsf/api/config/JsfModuleConfig.java
index f754d44..92972de 100644
--- a/deltaspike/modules/jsf/api/src/main/java/org/apache/deltaspike/jsf/api/config/JsfModuleConfig.java
+++ b/deltaspike/modules/jsf/api/src/main/java/org/apache/deltaspike/jsf/api/config/JsfModuleConfig.java
@@ -38,7 +38,9 @@ public class JsfModuleConfig implements DeltaSpikeConfig
 
     private static final long serialVersionUID = -487295181899986237L;
 
-    protected Boolean delegatedWindowHandlingEnabled;
+    private volatile Boolean initialized;
+    private boolean delegatedWindowHandlingEnabled;
+    private boolean jsf22Available;
 
     protected JsfModuleConfig()
     {
@@ -111,10 +113,7 @@ public class JsfModuleConfig implements DeltaSpikeConfig
      */
     public ClientWindowConfig.ClientWindowRenderMode getDefaultWindowMode()
     {
-        if (this.delegatedWindowHandlingEnabled == null)
-        {
-            lazyInitDelegatedWindowHandlingEnabled();
-        }
+        lazyInit();
 
         if (this.delegatedWindowHandlingEnabled)
         {
@@ -123,16 +122,6 @@ public class JsfModuleConfig implements DeltaSpikeConfig
         return null;
     }
 
-    protected synchronized void lazyInitDelegatedWindowHandlingEnabled()
-    {
-        if (this.delegatedWindowHandlingEnabled != null)
-        {
-            return;
-        }
-
-        this.delegatedWindowHandlingEnabled = isDelegatedWindowHandlingEnabled();
-    }
-
     /**
      * Defines the {@link javax.enterprise.Qualifier} which will be used to fire the
      * {@link org.apache.deltaspike.core.api.exception.control.event.ExceptionToCatchEvent}
@@ -150,22 +139,57 @@ public class JsfModuleConfig implements DeltaSpikeConfig
         return true;
     }
 
-    protected boolean isDelegatedWindowHandlingEnabled()
+    public boolean isJsf22Available()
     {
-        if (ClassUtils.tryToLoadClassForName(CLIENT_WINDOW_CLASS_NAME) == null)
+        lazyInit();
+        
+        return this.jsf22Available;
+    }
+    
+    public boolean isDelegatedWindowHandlingEnabled()
+    {
+        lazyInit();
+        
+        return this.delegatedWindowHandlingEnabled;
+    }
+    
+    private void lazyInit()
+    {
+        if (this.initialized == null)
         {
-            return false;
+            init();
         }
+    }
 
-        FacesContext facesContext = FacesContext.getCurrentInstance();
-
-        if (facesContext == null) // can happen in case of a very simple test-setup without
a mocked jsf container
+    protected synchronized void init()
+    {
+        if (this.initialized == null)
         {
-            return false;
+            this.jsf22Available = ClassUtils.tryToLoadClassForName(CLIENT_WINDOW_CLASS_NAME)
!= null;
+
+            if (!this.jsf22Available)
+            {
+                this.delegatedWindowHandlingEnabled = false;
+            }
+            else
+            {
+                FacesContext facesContext = FacesContext.getCurrentInstance();
+
+                // can happen in case of a very simple test-setup without a mocked jsf container
+                if (facesContext == null)
+                {
+                    this.delegatedWindowHandlingEnabled = false;
+                }
+                else
+                {
+                    
+                    String initParam = facesContext.getExternalContext().getInitParameter(CLIENT_WINDOW_CONFIG_KEY);
+                    this.delegatedWindowHandlingEnabled =
+                            !(initParam == null || "none".equalsIgnoreCase(initParam.trim()));
+                }
+            }
+            
+            this.initialized = true;
         }
-        String configuredWindowHandling = facesContext.getExternalContext()
-                                .getInitParameter(CLIENT_WINDOW_CONFIG_KEY);
-
-        return !(configuredWindowHandling == null || "none".equalsIgnoreCase(configuredWindowHandling.trim()));
     }
 }

http://git-wip-us.apache.org/repos/asf/deltaspike/blob/70c42ca9/deltaspike/modules/jsf/impl/src/main/java/org/apache/deltaspike/jsf/impl/component/window/DisableClientWindowHtmlRenderer.java
----------------------------------------------------------------------
diff --git a/deltaspike/modules/jsf/impl/src/main/java/org/apache/deltaspike/jsf/impl/component/window/DisableClientWindowHtmlRenderer.java
b/deltaspike/modules/jsf/impl/src/main/java/org/apache/deltaspike/jsf/impl/component/window/DisableClientWindowHtmlRenderer.java
index f4a3fb0..29ddd50 100644
--- a/deltaspike/modules/jsf/impl/src/main/java/org/apache/deltaspike/jsf/impl/component/window/DisableClientWindowHtmlRenderer.java
+++ b/deltaspike/modules/jsf/impl/src/main/java/org/apache/deltaspike/jsf/impl/component/window/DisableClientWindowHtmlRenderer.java
@@ -24,24 +24,41 @@ import javax.faces.context.FacesContext;
 import javax.faces.render.FacesRenderer;
 import javax.faces.render.Renderer;
 import org.apache.deltaspike.core.api.provider.BeanProvider;
+import org.apache.deltaspike.jsf.api.config.JsfModuleConfig;
+import org.apache.deltaspike.jsf.impl.scope.window.ClientWindowAdapter;
 import org.apache.deltaspike.jsf.spi.scope.window.ClientWindow;
 
 @FacesRenderer(componentFamily = DisableClientWindowComponent.COMPONENT_FAMILY,
         rendererType = DisableClientWindowComponent.COMPONENT_TYPE)
 public class DisableClientWindowHtmlRenderer extends Renderer
 {
-    private volatile ClientWindow clientWindow;
+    private volatile Boolean initialized;
+
+    private ClientWindow clientWindow;
+    private JsfModuleConfig jsfModuleConfig;
     
     @Override
     public void encodeChildren(FacesContext context, UIComponent component) throws IOException
     {
-        boolean clientWindowRenderModeEnabled = getClientWindow().isClientWindowRenderModeEnabled(context);
-
+        lazyInit();
+        
+        boolean clientWindowRenderModeEnabled = clientWindow.isClientWindowRenderModeEnabled(context);
+        
+        if (jsfModuleConfig.isJsf22Available())
+        {
+            Boolean jsfClientWindowRenderModeEnabled =
+                    ClientWindowAdapter.isJsf22ClientWindowRenderModeEnabled(context);
+            if (jsfClientWindowRenderModeEnabled != null)
+            {
+                clientWindowRenderModeEnabled = clientWindowRenderModeEnabled || jsfClientWindowRenderModeEnabled;
+            }
+        }
+        
         try
         {
             if (clientWindowRenderModeEnabled)
             {
-                getClientWindow().disableClientWindowRenderMode(context);
+                clientWindow.disableClientWindowRenderMode(context);
             }
 
             super.encodeChildren(context, component);
@@ -50,7 +67,7 @@ public class DisableClientWindowHtmlRenderer extends Renderer
         {
             if (clientWindowRenderModeEnabled)
             {
-                getClientWindow().enableClientWindowRenderMode(context);
+                clientWindow.enableClientWindowRenderMode(context);
             }
         }
     }
@@ -61,19 +78,20 @@ public class DisableClientWindowHtmlRenderer extends Renderer
         return true;
     }
     
-    private ClientWindow getClientWindow()
+    private void lazyInit()
     {
-        if (clientWindow == null)
+        if (this.initialized == null)
         {
-            synchronized (this)
-            {
-                if (clientWindow == null)
-                {
-                    clientWindow = BeanProvider.getContextualReference(ClientWindow.class);
-                }
-            }
+            init();
         }
+    }
 
-        return clientWindow;
+    protected synchronized void init()
+    {
+        if (this.initialized == null)
+        {
+            clientWindow = BeanProvider.getContextualReference(ClientWindow.class);
+            jsfModuleConfig = BeanProvider.getContextualReference(JsfModuleConfig.class);
+        }
     }
 }

http://git-wip-us.apache.org/repos/asf/deltaspike/blob/70c42ca9/deltaspike/modules/jsf/impl/src/main/java/org/apache/deltaspike/jsf/impl/listener/request/JsfClientWindowAwareLifecycleWrapper.java
----------------------------------------------------------------------
diff --git a/deltaspike/modules/jsf/impl/src/main/java/org/apache/deltaspike/jsf/impl/listener/request/JsfClientWindowAwareLifecycleWrapper.java
b/deltaspike/modules/jsf/impl/src/main/java/org/apache/deltaspike/jsf/impl/listener/request/JsfClientWindowAwareLifecycleWrapper.java
index 43de06e..1bb6db4 100644
--- a/deltaspike/modules/jsf/impl/src/main/java/org/apache/deltaspike/jsf/impl/listener/request/JsfClientWindowAwareLifecycleWrapper.java
+++ b/deltaspike/modules/jsf/impl/src/main/java/org/apache/deltaspike/jsf/impl/listener/request/JsfClientWindowAwareLifecycleWrapper.java
@@ -87,7 +87,8 @@ public class JsfClientWindowAwareLifecycleWrapper extends LifecycleWrapper
 
             if (!facesContext.getResponseComplete() && !"default".equals(windowId))
             {
-                facesContext.getExternalContext().setClientWindow(new ClientWindowAdapter(clientWindow));
+                facesContext.getExternalContext().setClientWindow(
+                        new ClientWindowAdapter(clientWindow, delegateWindowHandling));
             }
         }
     }

http://git-wip-us.apache.org/repos/asf/deltaspike/blob/70c42ca9/deltaspike/modules/jsf/impl/src/main/java/org/apache/deltaspike/jsf/impl/scope/window/ClientWindowAdapter.java
----------------------------------------------------------------------
diff --git a/deltaspike/modules/jsf/impl/src/main/java/org/apache/deltaspike/jsf/impl/scope/window/ClientWindowAdapter.java
b/deltaspike/modules/jsf/impl/src/main/java/org/apache/deltaspike/jsf/impl/scope/window/ClientWindowAdapter.java
index 29dc539..0a61a68 100644
--- a/deltaspike/modules/jsf/impl/src/main/java/org/apache/deltaspike/jsf/impl/scope/window/ClientWindowAdapter.java
+++ b/deltaspike/modules/jsf/impl/src/main/java/org/apache/deltaspike/jsf/impl/scope/window/ClientWindowAdapter.java
@@ -34,23 +34,34 @@ import java.util.Map;
 public class ClientWindowAdapter extends ClientWindow
 {
     private final org.apache.deltaspike.jsf.spi.scope.window.ClientWindow window;
+    private final boolean delegateWindowHandling;
 
-    public ClientWindowAdapter(org.apache.deltaspike.jsf.spi.scope.window.ClientWindow window)
+    public ClientWindowAdapter(org.apache.deltaspike.jsf.spi.scope.window.ClientWindow window,
+            boolean delegateWindowHandling)
     {
         this.window = window;
+        this.delegateWindowHandling = delegateWindowHandling;
     }
 
-    public static String getWindowIdFromJsf(FacesContext facesContext)
+    public static Boolean isJsf22ClientWindowRenderModeEnabled(FacesContext context)
     {
-        ClientWindow clientWindow = facesContext.getExternalContext().getClientWindow();
-
+        ClientWindow clientWindow = context.getExternalContext().getClientWindow();
         if (clientWindow != null)
         {
-            return clientWindow.getId();
+            if (clientWindow instanceof ClientWindowAdapter)
+            {
+                ClientWindowAdapter clientWindowAdapter = (ClientWindowAdapter) clientWindow;
+                return clientWindowAdapter.isOriginalClientWindowRenderModeEnabled(context);
+            }
+            else
+            {
+                return clientWindow.isClientWindowRenderModeEnabled(context);
+            }
         }
+        
         return null;
     }
-
+    
     @Override
     public void decode(FacesContext context)
     {
@@ -69,4 +80,20 @@ public class ClientWindowAdapter extends ClientWindow
         //currently not needed by the window-handling of DeltaSpike
         return Collections.emptyMap();
     }
+    
+    @Override
+    public boolean isClientWindowRenderModeEnabled(FacesContext context)
+    {
+        if (!delegateWindowHandling)
+        {
+            return false;
+        }
+        
+        return super.isClientWindowRenderModeEnabled(context);
+    }
+    
+    protected boolean isOriginalClientWindowRenderModeEnabled(FacesContext context)
+    {
+        return super.isClientWindowRenderModeEnabled(context);
+    }
 }

http://git-wip-us.apache.org/repos/asf/deltaspike/blob/70c42ca9/deltaspike/modules/jsf/impl/src/main/java/org/apache/deltaspike/jsf/impl/scope/window/strategy/AbstractClientWindowStrategy.java
----------------------------------------------------------------------
diff --git a/deltaspike/modules/jsf/impl/src/main/java/org/apache/deltaspike/jsf/impl/scope/window/strategy/AbstractClientWindowStrategy.java
b/deltaspike/modules/jsf/impl/src/main/java/org/apache/deltaspike/jsf/impl/scope/window/strategy/AbstractClientWindowStrategy.java
index af956a2..f3b9eca 100644
--- a/deltaspike/modules/jsf/impl/src/main/java/org/apache/deltaspike/jsf/impl/scope/window/strategy/AbstractClientWindowStrategy.java
+++ b/deltaspike/modules/jsf/impl/src/main/java/org/apache/deltaspike/jsf/impl/scope/window/strategy/AbstractClientWindowStrategy.java
@@ -27,6 +27,7 @@ import javax.inject.Inject;
 import javax.servlet.http.HttpServletRequest;
 import org.apache.deltaspike.core.spi.scope.window.WindowContext;
 import org.apache.deltaspike.jsf.api.config.JsfModuleConfig;
+import org.apache.deltaspike.jsf.impl.scope.window.ClientWindowAdapter;
 import org.apache.deltaspike.jsf.impl.util.ClientWindowHelper;
 import org.apache.deltaspike.jsf.spi.scope.window.ClientWindow;
 import org.apache.deltaspike.jsf.spi.scope.window.ClientWindowConfig;
@@ -144,6 +145,14 @@ public abstract class AbstractClientWindowStrategy implements ClientWindow
             Map<Object, Object> attrMap = facesContext.getAttributes();
             attrMap.put(PER_USE_CLIENT_WINDOW_URL_QUERY_PARAMETER_DISABLED_KEY, Boolean.TRUE);
         }
+
+        if (jsfModuleConfig.isJsf22Available())
+        {
+            if (facesContext.getExternalContext().getClientWindow() != null)
+            {
+                facesContext.getExternalContext().getClientWindow().disableClientWindowRenderMode(facesContext);
+            }
+        }
     }
 
     @Override
@@ -154,11 +163,28 @@ public abstract class AbstractClientWindowStrategy implements ClientWindow
             Map<Object, Object> attrMap = facesContext.getAttributes();
             attrMap.remove(PER_USE_CLIENT_WINDOW_URL_QUERY_PARAMETER_DISABLED_KEY);
         }
+        
+        if (jsfModuleConfig.isJsf22Available())
+        {
+            if (facesContext.getExternalContext().getClientWindow() != null)
+            {
+                facesContext.getExternalContext().getClientWindow().enableClientWindowRenderMode(facesContext);
+            }
+        }
     }
 
     @Override
     public boolean isClientWindowRenderModeEnabled(FacesContext facesContext)
     {
+        // skip dswid rendering if JSF2.2 render mode is disabled
+        if (jsfModuleConfig.isJsf22Available())
+        {
+            if (ClientWindowAdapter.isJsf22ClientWindowRenderModeEnabled(facesContext) ==
false)
+            {
+                return false;
+            }
+        }
+
         if (isSupportClientWindowRenderingMode())
         {
             Map<Object, Object> attrMap = facesContext.getAttributes();

http://git-wip-us.apache.org/repos/asf/deltaspike/blob/70c42ca9/deltaspike/modules/jsf/impl/src/main/java/org/apache/deltaspike/jsf/impl/scope/window/strategy/DelegatedWindowStrategy.java
----------------------------------------------------------------------
diff --git a/deltaspike/modules/jsf/impl/src/main/java/org/apache/deltaspike/jsf/impl/scope/window/strategy/DelegatedWindowStrategy.java
b/deltaspike/modules/jsf/impl/src/main/java/org/apache/deltaspike/jsf/impl/scope/window/strategy/DelegatedWindowStrategy.java
index af7bd43..2cb4b37 100644
--- a/deltaspike/modules/jsf/impl/src/main/java/org/apache/deltaspike/jsf/impl/scope/window/strategy/DelegatedWindowStrategy.java
+++ b/deltaspike/modules/jsf/impl/src/main/java/org/apache/deltaspike/jsf/impl/scope/window/strategy/DelegatedWindowStrategy.java
@@ -21,7 +21,6 @@ package org.apache.deltaspike.jsf.impl.scope.window.strategy;
 import javax.enterprise.context.Dependent;
 import javax.enterprise.inject.Typed;
 import javax.faces.context.FacesContext;
-import org.apache.deltaspike.jsf.impl.scope.window.ClientWindowAdapter;
 
 @Dependent
 @Typed(DelegatedWindowStrategy.class)
@@ -30,24 +29,11 @@ public class DelegatedWindowStrategy extends AbstractClientWindowStrategy
     @Override
     protected String getOrCreateWindowId(FacesContext facesContext)
     {
-        return ClientWindowAdapter.getWindowIdFromJsf(facesContext);
-    }
-
-    @Override
-    public void disableClientWindowRenderMode(FacesContext facesContext)
-    {
-        facesContext.getExternalContext().getClientWindow().disableClientWindowRenderMode(facesContext);
-    }
-
-    @Override
-    public void enableClientWindowRenderMode(FacesContext facesContext)
-    {
-        facesContext.getExternalContext().getClientWindow().enableClientWindowRenderMode(facesContext);
-    }
-    
-    @Override
-    public boolean isClientWindowRenderModeEnabled(FacesContext facesContext)
-    {
-        return facesContext.getExternalContext().getClientWindow().isClientWindowRenderModeEnabled(facesContext);
+        if (facesContext.getExternalContext().getClientWindow() != null)
+        {
+            return facesContext.getExternalContext().getClientWindow().getId();
+        }
+        
+        return null;
     }
 }


Mime
View raw message