deltaspike-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From tandrasc...@apache.org
Subject git commit: DELTASPIKE-502 added client side logic
Date Sun, 19 Jan 2014 11:53:58 GMT
Updated Branches:
  refs/heads/master 895c6f00e -> 1ee1d9cbf


DELTASPIKE-502 added client side logic

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

Branch: refs/heads/master
Commit: 1ee1d9cbf645abb9f7830867b336438d92a35201
Parents: 895c6f0
Author: tandraschko <tandraschko@apache.org>
Authored: Sun Jan 19 12:53:19 2014 +0100
Committer: tandraschko <tandraschko@apache.org>
Committed: Sun Jan 19 12:53:19 2014 +0100

----------------------------------------------------------------------
 .../component/window/WindowIdHtmlRenderer.java  | 22 ++++++++++++-
 .../impl/scope/window/DefaultClientWindow.java  |  5 +--
 .../resources/deltaspike/windowhandler.js       | 33 +++++++++++++-------
 .../main/resources/static/windowhandler.html    |  2 +-
 4 files changed, 47 insertions(+), 15 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/deltaspike/blob/1ee1d9cb/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 8ef0645..c5297bb 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
@@ -29,6 +29,7 @@ import java.io.IOException;
 
 import org.apache.deltaspike.core.api.provider.BeanProvider;
 import org.apache.deltaspike.core.spi.scope.window.WindowContext;
+import org.apache.deltaspike.jsf.spi.scope.window.ClientWindowConfig;
 
 @FacesRenderer(componentFamily = WindowIdComponent.COMPONENT_FAMILY, rendererType = WindowIdComponent.COMPONENT_TYPE)
 @ResourceDependencies( {
@@ -37,6 +38,7 @@ import org.apache.deltaspike.core.spi.scope.window.WindowContext;
 public class WindowIdHtmlRenderer extends Renderer
 {
     private volatile WindowContext windowContext;
+    private volatile ClientWindowConfig clientWindowConfig;
 
     /**
      * 'deltaspikeJsWindowId' will be used to:
@@ -52,11 +54,13 @@ public class WindowIdHtmlRenderer extends Renderer
         super.encodeBegin(context, component);
 
         String windowId = getWindowContext().getCurrentWindowId();
+        String mode = getClientWindowConfig().getClientWindowRenderMode(context).name();
 
         ResponseWriter writer = context.getResponseWriter();
         writer.startElement("script", component);
         writer.writeAttribute("type", "text/javascript", null);
-        writer.write("window.deltaspikeJsWindowId=" + windowId + ";");
+        writer.write("window.deltaspikeWindowId='" + windowId + "';");
+        writer.write("window.deltaspikeClientWindowRenderMode='" + mode + "';");
 
         writer.endElement("script");
     }
@@ -76,4 +80,20 @@ public class WindowIdHtmlRenderer extends Renderer
 
         return windowContext;
     }
+    
+    private ClientWindowConfig getClientWindowConfig()
+    {
+        if (clientWindowConfig == null)
+        {
+            synchronized (this)
+            {
+                if (clientWindowConfig == null)
+                {
+                    clientWindowConfig = BeanProvider.getContextualReference(ClientWindowConfig.class);
+                }
+            }
+        }
+
+        return clientWindowConfig;
+    }
 }

http://git-wip-us.apache.org/repos/asf/deltaspike/blob/1ee1d9cb/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 3b5fc47..71c0852 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
@@ -36,6 +36,7 @@ import java.io.OutputStream;
 import java.util.HashMap;
 import java.util.Map;
 import java.util.Random;
+import org.apache.deltaspike.core.util.StringUtils;
 
 import static org.apache.deltaspike.jsf.spi.scope.window.ClientWindowConfig.ClientWindowRenderMode;
 
@@ -117,12 +118,12 @@ public class DefaultClientWindow implements ClientWindow
 
             String windowId = (String) ClientWindowHelper.getInitialRedirectWindowId(facesContext);
 
-            if (windowId == null)
+            if (StringUtils.isEmpty(windowId))
             {
                 windowId = externalContext.getRequestParameterMap().get(DELTASPIKE_WINDOW_ID_URL_PARAM);
             }
 
-            if (windowId == null)
+            if (StringUtils.isEmpty(windowId))
             {
                 ClientWindowHelper.handleInitialRedirect(facesContext, generateNewWindowId());
                 facesContext.responseComplete();

http://git-wip-us.apache.org/repos/asf/deltaspike/blob/1ee1d9cb/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 c7f6bca..1d1a664 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
@@ -74,7 +74,7 @@ function equalsIgnoreCase(source, destination) {
 
 /** This method will be called onWindowLoad and after AJAX success */
 function applyWindowId() {
-    if (isHtml5()) { // onClick handling
+    if (window.deltaspikeClientWindowRenderMode === 'CLIENTWINDOW' && isHtml5())
{ // onClick handling
         var links = document.getElementsByTagName("a");
         for (var i = 0; i < links.length; i++) {
             if (!links[i].onclick) {
@@ -108,7 +108,7 @@ function applyWindowId() {
             form.appendChild(windowIdHolder);
         }
 
-        windowIdHolder.value = window.deltaspikeJsWindowId;
+        windowIdHolder.value = window.deltaspikeWindowId;
     }
 }
 
@@ -155,9 +155,18 @@ function setUrlParam(baseUrl, paramName, paramValue) {
 // this method runs to ensure that windowIds get checked even if no windowhandler.html is
used
 function assertWindowId() {
     if (!window.name || window.name.length < 1) {
-        url = setUrlParam(window.location.href, 'windowId', null);
         window.name = 'tempWindowId';
-        window.location = url;
+        window.location = setUrlParam(window.location.href, 'dswid', null);
+    }
+    else if (window.deltaspikeClientWindowRenderMode === 'LAZY') {
+        var dswid = getUrlParameter('dswid');
+        if (window.name === 'tempWindowId') {
+            window.name = dswid;
+        }
+        else if (window.name !== dswid) {
+            // redirect with current window.name / windowId
+            window.location = setUrlParam(window.location.href, 'dswid', window.name);
+        }
     }
 }
 
@@ -181,13 +190,15 @@ var ajaxOnClick = function ajaxDecorateClick(event) {
 var oldWindowOnLoad = window.onload;
 
 window.onload = function(evt) {
-    try {
-        (oldWindowOnLoad)? oldWindowOnLoad(evt): null;
-    } finally {
-        eraseRequestCookie(); // manually erase the old dsRid cookie because Firefox doesn't
do it properly
-        assertWindowId();
-        applyWindowId();
-        jsf.ajax.addOnEvent(ajaxOnClick);
+    if (window.deltaspikeClientWindowRenderMode === 'LAZY' || window.deltaspikeClientWindowRenderMode
=== 'CLIENTWINDOW') {
+        try {
+            (oldWindowOnLoad)? oldWindowOnLoad(evt): null;
+        } finally {
+            eraseRequestCookie(); // manually erase the old dsRid cookie because Firefox
doesn't do it properly
+            assertWindowId();
+            applyWindowId();
+            jsf.ajax.addOnEvent(ajaxOnClick);
+        }
     }
 }
 })();

http://git-wip-us.apache.org/repos/asf/deltaspike/blob/1ee1d9cb/deltaspike/modules/jsf/impl/src/main/resources/static/windowhandler.html
----------------------------------------------------------------------
diff --git a/deltaspike/modules/jsf/impl/src/main/resources/static/windowhandler.html b/deltaspike/modules/jsf/impl/src/main/resources/static/windowhandler.html
index 911fd44..e49b01a 100644
--- a/deltaspike/modules/jsf/impl/src/main/resources/static/windowhandler.html
+++ b/deltaspike/modules/jsf/impl/src/main/resources/static/windowhandler.html
@@ -164,7 +164,7 @@ window.onload = function() {
     var newUrl = setUrlParam(window.location.href, "dsRid", requestToken);
 
     // we still add hte windowId page param to support lazy windowId dropping for some clients
-    newUrl = setUrlParam(newUrl, "windowId", urlId);
+    newUrl = setUrlParam(newUrl, "dswid", urlId);
 
     document.cookie = 'dsWindowId-' + requestToken + '=' + windowId + expires+"; path=/";
 


Mime
View raw message