You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@deltaspike.apache.org by ta...@apache.org on 2015/11/25 21:34:28 UTC

deltaspike git commit: DELTASPIKE-1029 avoid windowhandler streaming in ajax redirects

Repository: deltaspike
Updated Branches:
  refs/heads/master 9ab5c5cac -> 70165b048


DELTASPIKE-1029 avoid windowhandler streaming in ajax redirects

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

Branch: refs/heads/master
Commit: 70165b0481990aa55a8ecd56578a9aa82ec2c716
Parents: 9ab5c5c
Author: Thomas Andraschko <ta...@apache.org>
Authored: Wed Nov 25 21:34:17 2015 +0100
Committer: Thomas Andraschko <ta...@apache.org>
Committed: Wed Nov 25 21:34:17 2015 +0100

----------------------------------------------------------------------
 .../jsf/spi/scope/window/ClientWindow.java      |  5 ++
 .../spi/scope/window/ClientWindowConfig.java    |  8 ---
 .../scope/window/DefaultClientWindowConfig.java |  8 +--
 .../component/window/WindowIdHtmlRenderer.java  |  2 -
 .../request/DeltaSpikeFacesContextWrapper.java  |  9 +++
 .../DeltaSpikePartialResponseWriter.java        | 71 ++++++++++++++++++++
 .../DeltaSpikePartialViewContext.java           | 53 +++++++++++++++
 .../impl/scope/window/DefaultClientWindow.java  |  6 ++
 .../strategy/AbstractClientWindowStrategy.java  |  6 ++
 .../strategy/ClientSideWindowStrategy.java      | 34 ++++++++++
 .../jsf/impl/util/ClientWindowHelper.java       |  2 +-
 .../resources/deltaspike/windowhandler.js       | 16 -----
 12 files changed, 186 insertions(+), 34 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/deltaspike/blob/70165b04/deltaspike/modules/jsf/api/src/main/java/org/apache/deltaspike/jsf/spi/scope/window/ClientWindow.java
----------------------------------------------------------------------
diff --git a/deltaspike/modules/jsf/api/src/main/java/org/apache/deltaspike/jsf/spi/scope/window/ClientWindow.java b/deltaspike/modules/jsf/api/src/main/java/org/apache/deltaspike/jsf/spi/scope/window/ClientWindow.java
index db15095..82dbf14 100644
--- a/deltaspike/modules/jsf/api/src/main/java/org/apache/deltaspike/jsf/spi/scope/window/ClientWindow.java
+++ b/deltaspike/modules/jsf/api/src/main/java/org/apache/deltaspike/jsf/spi/scope/window/ClientWindow.java
@@ -76,4 +76,9 @@ public interface ClientWindow
      * @return true if the implementation possible sends an initial redirect.
      */
     boolean isInitialRedirectSupported(FacesContext facesContext);
+    
+    /**
+     * @return The new redirect url.
+     */
+    String interceptRedirect(FacesContext facesContext, String url);
 }

http://git-wip-us.apache.org/repos/asf/deltaspike/blob/70165b04/deltaspike/modules/jsf/api/src/main/java/org/apache/deltaspike/jsf/spi/scope/window/ClientWindowConfig.java
----------------------------------------------------------------------
diff --git a/deltaspike/modules/jsf/api/src/main/java/org/apache/deltaspike/jsf/spi/scope/window/ClientWindowConfig.java b/deltaspike/modules/jsf/api/src/main/java/org/apache/deltaspike/jsf/spi/scope/window/ClientWindowConfig.java
index 65ef633..bf81d57 100644
--- a/deltaspike/modules/jsf/api/src/main/java/org/apache/deltaspike/jsf/spi/scope/window/ClientWindowConfig.java
+++ b/deltaspike/modules/jsf/api/src/main/java/org/apache/deltaspike/jsf/spi/scope/window/ClientWindowConfig.java
@@ -97,14 +97,6 @@ public interface ClientWindowConfig extends Serializable
 
     /**
      * @return Whether the DOM tree should stored in the localStorage for the windowhandler.html
-     *         when sending a AJAX request.
-     *         Currently it's only used by {@link ClientWindowRenderMode#CLIENTWINDOW}.
-     * @see windowhandler.html
-     */
-    boolean isClientWindowStoreWindowTreeEnabledOnAjaxRequest();
-    
-    /**
-     * @return Whether the DOM tree should stored in the localStorage for the windowhandler.html
      *         when clicking on a button.
      *         Currently it's only used by {@link ClientWindowRenderMode#CLIENTWINDOW}.
      * @see windowhandler.html

http://git-wip-us.apache.org/repos/asf/deltaspike/blob/70165b04/deltaspike/modules/jsf/api/src/main/java/org/apache/deltaspike/jsf/spi/scope/window/DefaultClientWindowConfig.java
----------------------------------------------------------------------
diff --git a/deltaspike/modules/jsf/api/src/main/java/org/apache/deltaspike/jsf/spi/scope/window/DefaultClientWindowConfig.java b/deltaspike/modules/jsf/api/src/main/java/org/apache/deltaspike/jsf/spi/scope/window/DefaultClientWindowConfig.java
index 7232767..f0316aa 100644
--- a/deltaspike/modules/jsf/api/src/main/java/org/apache/deltaspike/jsf/spi/scope/window/DefaultClientWindowConfig.java
+++ b/deltaspike/modules/jsf/api/src/main/java/org/apache/deltaspike/jsf/spi/scope/window/DefaultClientWindowConfig.java
@@ -235,13 +235,7 @@ public class DefaultClientWindowConfig implements ClientWindowConfig
     {
         return true;
     }
-    
-    @Override
-    public boolean isClientWindowStoreWindowTreeEnabledOnAjaxRequest()
-    {
-        return false;
-    }
-    
+
     @Override
     public boolean isClientWindowStoreWindowTreeEnabledOnButtonClick()
     {

http://git-wip-us.apache.org/repos/asf/deltaspike/blob/70165b04/deltaspike/modules/jsf/impl/src/main/java/org/apache/deltaspike/jsf/impl/component/window/WindowIdHtmlRenderer.java
----------------------------------------------------------------------
diff --git a/deltaspike/modules/jsf/impl/src/main/java/org/apache/deltaspike/jsf/impl/component/window/WindowIdHtmlRenderer.java b/deltaspike/modules/jsf/impl/src/main/java/org/apache/deltaspike/jsf/impl/component/window/WindowIdHtmlRenderer.java
index 1858aac..63d5984 100644
--- a/deltaspike/modules/jsf/impl/src/main/java/org/apache/deltaspike/jsf/impl/component/window/WindowIdHtmlRenderer.java
+++ b/deltaspike/modules/jsf/impl/src/main/java/org/apache/deltaspike/jsf/impl/component/window/WindowIdHtmlRenderer.java
@@ -82,8 +82,6 @@ public class WindowIdHtmlRenderer extends Renderer
                 + clientWindowConfig.isClientWindowStoreWindowTreeEnabledOnLinkClick());
         writer.write(",'storeWindowTreeOnButtonClick':"
                 + clientWindowConfig.isClientWindowStoreWindowTreeEnabledOnButtonClick());
-        writer.write(",'storeWindowTreeOnAjaxRequest':"
-                + clientWindowConfig.isClientWindowStoreWindowTreeEnabledOnAjaxRequest());
 
         // see #729
         if (!delegatedWindowMode && clientWindow.isInitialRedirectSupported(context))

http://git-wip-us.apache.org/repos/asf/deltaspike/blob/70165b04/deltaspike/modules/jsf/impl/src/main/java/org/apache/deltaspike/jsf/impl/listener/request/DeltaSpikeFacesContextWrapper.java
----------------------------------------------------------------------
diff --git a/deltaspike/modules/jsf/impl/src/main/java/org/apache/deltaspike/jsf/impl/listener/request/DeltaSpikeFacesContextWrapper.java b/deltaspike/modules/jsf/impl/src/main/java/org/apache/deltaspike/jsf/impl/listener/request/DeltaSpikeFacesContextWrapper.java
index 2e5d582..e2301cc 100644
--- a/deltaspike/modules/jsf/impl/src/main/java/org/apache/deltaspike/jsf/impl/listener/request/DeltaSpikeFacesContextWrapper.java
+++ b/deltaspike/modules/jsf/impl/src/main/java/org/apache/deltaspike/jsf/impl/listener/request/DeltaSpikeFacesContextWrapper.java
@@ -38,8 +38,10 @@ import javax.faces.context.FacesContextWrapper;
 import java.util.List;
 import java.util.Map;
 import java.util.concurrent.CopyOnWriteArrayList;
+import javax.faces.context.PartialViewContext;
 import org.apache.deltaspike.core.util.metadata.AnnotationInstanceProvider;
 import org.apache.deltaspike.jsf.impl.exception.control.BridgeExceptionHandlerWrapper;
+import org.apache.deltaspike.jsf.impl.navigation.DeltaSpikePartialViewContext;
 
 import org.apache.deltaspike.jsf.impl.navigation.NavigationHandlerAwareApplication;
 import org.apache.deltaspike.jsf.impl.security.SecurityAwareViewHandler;
@@ -100,6 +102,13 @@ class DeltaSpikeFacesContextWrapper extends FacesContextWrapper
     }
 
     @Override
+    public PartialViewContext getPartialViewContext()
+    {
+        PartialViewContext partialViewContext = getWrapped().getPartialViewContext();
+        return new DeltaSpikePartialViewContext(partialViewContext);
+    }
+    
+    @Override
     public ExceptionHandler getExceptionHandler()
     {
         lazyInit();

http://git-wip-us.apache.org/repos/asf/deltaspike/blob/70165b04/deltaspike/modules/jsf/impl/src/main/java/org/apache/deltaspike/jsf/impl/navigation/DeltaSpikePartialResponseWriter.java
----------------------------------------------------------------------
diff --git a/deltaspike/modules/jsf/impl/src/main/java/org/apache/deltaspike/jsf/impl/navigation/DeltaSpikePartialResponseWriter.java b/deltaspike/modules/jsf/impl/src/main/java/org/apache/deltaspike/jsf/impl/navigation/DeltaSpikePartialResponseWriter.java
new file mode 100644
index 0000000..0c2e27c
--- /dev/null
+++ b/deltaspike/modules/jsf/impl/src/main/java/org/apache/deltaspike/jsf/impl/navigation/DeltaSpikePartialResponseWriter.java
@@ -0,0 +1,71 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.deltaspike.jsf.impl.navigation;
+
+import java.io.IOException;
+import javax.faces.context.FacesContext;
+import javax.faces.context.PartialResponseWriter;
+import org.apache.deltaspike.core.api.provider.BeanProvider;
+import org.apache.deltaspike.jsf.spi.scope.window.ClientWindow;
+
+public class DeltaSpikePartialResponseWriter extends PartialResponseWriter
+{
+    private ClientWindow clientWindow;
+
+    private volatile Boolean initialized;
+
+    public DeltaSpikePartialResponseWriter(PartialResponseWriter wrapped)
+    {
+        super(wrapped);
+    }
+    
+    @Override
+    public void redirect(String url) throws IOException
+    {
+        lazyInit();
+
+        if (clientWindow == null)
+        {
+            super.redirect(url);
+        }
+        else
+        {
+            super.redirect(clientWindow.interceptRedirect(FacesContext.getCurrentInstance(), url));
+        }
+    }
+    
+    private void lazyInit()
+    {
+        if (this.initialized == null)
+        {
+            init();
+        }
+    }
+
+    private synchronized void init()
+    {
+        // switch into paranoia mode
+        if (this.initialized == null)
+        {
+            clientWindow = BeanProvider.getContextualReference(ClientWindow.class, true);
+
+            this.initialized = true;
+        }
+    }
+}

http://git-wip-us.apache.org/repos/asf/deltaspike/blob/70165b04/deltaspike/modules/jsf/impl/src/main/java/org/apache/deltaspike/jsf/impl/navigation/DeltaSpikePartialViewContext.java
----------------------------------------------------------------------
diff --git a/deltaspike/modules/jsf/impl/src/main/java/org/apache/deltaspike/jsf/impl/navigation/DeltaSpikePartialViewContext.java b/deltaspike/modules/jsf/impl/src/main/java/org/apache/deltaspike/jsf/impl/navigation/DeltaSpikePartialViewContext.java
new file mode 100644
index 0000000..8fc04aa
--- /dev/null
+++ b/deltaspike/modules/jsf/impl/src/main/java/org/apache/deltaspike/jsf/impl/navigation/DeltaSpikePartialViewContext.java
@@ -0,0 +1,53 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.deltaspike.jsf.impl.navigation;
+
+import javax.faces.context.PartialResponseWriter;
+import javax.faces.context.PartialViewContext;
+import javax.faces.context.PartialViewContextWrapper;
+
+public class DeltaSpikePartialViewContext extends PartialViewContextWrapper
+{
+    private final PartialViewContext wrapped;
+    private PartialResponseWriter writer = null;
+
+    public DeltaSpikePartialViewContext(PartialViewContext wrapped)
+    {
+        this.wrapped = wrapped;
+    }
+
+    @Override
+    public PartialResponseWriter getPartialResponseWriter()
+    {
+        if (writer == null)
+        {
+            PartialResponseWriter parentWriter = getWrapped().getPartialResponseWriter();
+            writer = new DeltaSpikePartialResponseWriter(parentWriter);
+        }
+
+        return writer;
+    }
+
+    
+    @Override
+    public PartialViewContext getWrapped()
+    {
+        return this.wrapped;
+    }
+}

http://git-wip-us.apache.org/repos/asf/deltaspike/blob/70165b04/deltaspike/modules/jsf/impl/src/main/java/org/apache/deltaspike/jsf/impl/scope/window/DefaultClientWindow.java
----------------------------------------------------------------------
diff --git a/deltaspike/modules/jsf/impl/src/main/java/org/apache/deltaspike/jsf/impl/scope/window/DefaultClientWindow.java b/deltaspike/modules/jsf/impl/src/main/java/org/apache/deltaspike/jsf/impl/scope/window/DefaultClientWindow.java
index b517af9..c20286b 100644
--- a/deltaspike/modules/jsf/impl/src/main/java/org/apache/deltaspike/jsf/impl/scope/window/DefaultClientWindow.java
+++ b/deltaspike/modules/jsf/impl/src/main/java/org/apache/deltaspike/jsf/impl/scope/window/DefaultClientWindow.java
@@ -94,6 +94,12 @@ public class DefaultClientWindow implements ClientWindow
         return getClientWindow(facesContext).isInitialRedirectSupported(facesContext);
     }
 
+    @Override
+    public String interceptRedirect(FacesContext facesContext, String url)
+    {
+        return getClientWindow(facesContext).interceptRedirect(facesContext, url);
+    }
+
     protected ClientWindow getClientWindow(FacesContext facesContext)
     {
         ClientWindowRenderMode clientWindowRenderMode = clientWindowConfig.getClientWindowRenderMode(facesContext);

http://git-wip-us.apache.org/repos/asf/deltaspike/blob/70165b04/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 ea70794..97aca91 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
@@ -210,4 +210,10 @@ public abstract class AbstractClientWindowStrategy implements ClientWindow
     {
         return null;
     }
+    
+    @Override
+    public String interceptRedirect(FacesContext facesContext, String url)
+    {
+        return url;
+    }
 }

http://git-wip-us.apache.org/repos/asf/deltaspike/blob/70165b04/deltaspike/modules/jsf/impl/src/main/java/org/apache/deltaspike/jsf/impl/scope/window/strategy/ClientSideWindowStrategy.java
----------------------------------------------------------------------
diff --git a/deltaspike/modules/jsf/impl/src/main/java/org/apache/deltaspike/jsf/impl/scope/window/strategy/ClientSideWindowStrategy.java b/deltaspike/modules/jsf/impl/src/main/java/org/apache/deltaspike/jsf/impl/scope/window/strategy/ClientSideWindowStrategy.java
index 6d2598a..3b48e2a 100644
--- a/deltaspike/modules/jsf/impl/src/main/java/org/apache/deltaspike/jsf/impl/scope/window/strategy/ClientSideWindowStrategy.java
+++ b/deltaspike/modules/jsf/impl/src/main/java/org/apache/deltaspike/jsf/impl/scope/window/strategy/ClientSideWindowStrategy.java
@@ -196,4 +196,38 @@ public class ClientSideWindowStrategy extends AbstractClientWindowStrategy
 
         return "";
     }
+    
+    @Override
+    public String interceptRedirect(FacesContext facesContext, String url)
+    {
+        if (facesContext.getPartialViewContext().isAjaxRequest())
+        {
+            String requestToken = newRequestToken();
+            String windowId = getWindowId(facesContext);
+            
+            ClientWindowHelper.addRequestWindowIdCookie(facesContext,
+                    requestToken,
+                    windowId);
+
+            url = JsfUtils.addParameter(facesContext.getExternalContext(),
+                    url,
+                    true,
+                    ClientWindowHelper.RequestParameters.GET_WINDOW_ID,
+                    windowId);
+            url = JsfUtils.addParameter(facesContext.getExternalContext(),
+                    url,
+                    true,
+                    ClientWindowHelper.RequestParameters.REQUEST_TOKEN,
+                    requestToken);
+
+            return url;
+        }
+        
+        return url;
+    }
+    
+    protected String newRequestToken()
+    {
+        return "" + ((int) Math.floor(Math.random() * 999));
+    }
 }

http://git-wip-us.apache.org/repos/asf/deltaspike/blob/70165b04/deltaspike/modules/jsf/impl/src/main/java/org/apache/deltaspike/jsf/impl/util/ClientWindowHelper.java
----------------------------------------------------------------------
diff --git a/deltaspike/modules/jsf/impl/src/main/java/org/apache/deltaspike/jsf/impl/util/ClientWindowHelper.java b/deltaspike/modules/jsf/impl/src/main/java/org/apache/deltaspike/jsf/impl/util/ClientWindowHelper.java
index 971633b..59b15d9 100644
--- a/deltaspike/modules/jsf/impl/src/main/java/org/apache/deltaspike/jsf/impl/util/ClientWindowHelper.java
+++ b/deltaspike/modules/jsf/impl/src/main/java/org/apache/deltaspike/jsf/impl/util/ClientWindowHelper.java
@@ -81,7 +81,7 @@ public abstract class ClientWindowHelper
         //only #encodeResourceURL is portable currently
         url = facesContext.getExternalContext().encodeResourceURL(url);
 
-        // rember the initial redirect windowId till the next request - see #729
+        // remember the initial redirect windowId till the next request - see #729
         addRequestWindowIdCookie(facesContext, newWindowId, newWindowId);
 
         try

http://git-wip-us.apache.org/repos/asf/deltaspike/blob/70165b04/deltaspike/modules/jsf/impl/src/main/resources/META-INF/resources/deltaspike/windowhandler.js
----------------------------------------------------------------------
diff --git a/deltaspike/modules/jsf/impl/src/main/resources/META-INF/resources/deltaspike/windowhandler.js b/deltaspike/modules/jsf/impl/src/main/resources/META-INF/resources/deltaspike/windowhandler.js
index eac5c98..5d3e9d1 100644
--- a/deltaspike/modules/jsf/impl/src/main/resources/META-INF/resources/deltaspike/windowhandler.js
+++ b/deltaspike/modules/jsf/impl/src/main/resources/META-INF/resources/deltaspike/windowhandler.js
@@ -81,22 +81,6 @@ window.dswh = window.dswh || {
                 this.overwriteButtonOnClickEvents();
 
                 dswh.utils.appendHiddenWindowIdToForms();
-
-                if (ajax === false && dswh.utils.isHtml5() && dswh.cfg.storeWindowTreeOnAjaxRequest) {
-                    // JSF ajax callback
-                    jsf.ajax.addOnEvent(function(event) {
-                        if (event.status === "begin") {
-                            dswh.strategy.CLIENTWINDOW.storeWindowTree();
-                        }
-                    });
-
-                    // PF ajax callback
-                    if (window.$ && window.PrimeFaces) {
-                        $(document).on('pfAjaxSend', function () {
-                            dswh.strategy.CLIENTWINDOW.storeWindowTree();
-                        });
-                    }
-                }
             },
 
             assertWindowId : function() {