You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@myfaces.apache.org by st...@apache.org on 2012/05/14 14:15:25 UTC

svn commit: r1338175 - in /myfaces/extensions/cdi/trunk/jee-modules/jsf-module/impl/src/main: java/org/apache/myfaces/extensions/cdi/jsf/impl/scope/conversation/ resources/META-INF/resources/js/ resources/static/

Author: struberg
Date: Mon May 14 12:15:25 2012
New Revision: 1338175

URL: http://svn.apache.org/viewvc?rev=1338175&view=rev
Log:
EXTCDI-284 add support for already existing window.name value

This will enable
* href target=
* multi-framework apps
* copy&paste between different tabs
* opening a bookmark on an existing page

Modified:
    myfaces/extensions/cdi/trunk/jee-modules/jsf-module/impl/src/main/java/org/apache/myfaces/extensions/cdi/jsf/impl/scope/conversation/ClientSideWindowHandler.java
    myfaces/extensions/cdi/trunk/jee-modules/jsf-module/impl/src/main/resources/META-INF/resources/js/windowhandler.js
    myfaces/extensions/cdi/trunk/jee-modules/jsf-module/impl/src/main/resources/static/windowhandler.html

Modified: myfaces/extensions/cdi/trunk/jee-modules/jsf-module/impl/src/main/java/org/apache/myfaces/extensions/cdi/jsf/impl/scope/conversation/ClientSideWindowHandler.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/ClientSideWindowHandler.java?rev=1338175&r1=1338174&r2=1338175&view=diff
==============================================================================
--- myfaces/extensions/cdi/trunk/jee-modules/jsf-module/impl/src/main/java/org/apache/myfaces/extensions/cdi/jsf/impl/scope/conversation/ClientSideWindowHandler.java (original)
+++ myfaces/extensions/cdi/trunk/jee-modules/jsf-module/impl/src/main/java/org/apache/myfaces/extensions/cdi/jsf/impl/scope/conversation/ClientSideWindowHandler.java Mon May 14 12:15:25 2012
@@ -179,8 +179,8 @@ public class ClientSideWindowHandler ext
             windowHandlerHtml = windowHandlerHtml.replace(WINDOW_ID_REPLACE_PATTERN, windowId);
 
             // set the noscript-URL for users with no JavaScript
-            windowHandlerHtml = windowHandlerHtml.replace(
-                    NOSCRIPT_URL_REPLACE_PATTERN, getNoscriptUrl(externalContext));
+            windowHandlerHtml =
+                    windowHandlerHtml.replace(NOSCRIPT_URL_REPLACE_PATTERN, getNoscriptUrl(externalContext));
 
             OutputStream os = httpResponse.getOutputStream();
             try

Modified: myfaces/extensions/cdi/trunk/jee-modules/jsf-module/impl/src/main/resources/META-INF/resources/js/windowhandler.js
URL: http://svn.apache.org/viewvc/myfaces/extensions/cdi/trunk/jee-modules/jsf-module/impl/src/main/resources/META-INF/resources/js/windowhandler.js?rev=1338175&r1=1338174&r2=1338175&view=diff
==============================================================================
--- myfaces/extensions/cdi/trunk/jee-modules/jsf-module/impl/src/main/resources/META-INF/resources/js/windowhandler.js (original)
+++ myfaces/extensions/cdi/trunk/jee-modules/jsf-module/impl/src/main/resources/META-INF/resources/js/windowhandler.js Mon May 14 12:15:25 2012
@@ -78,9 +78,8 @@ function applyOnClick() {
         if (!links[i].onclick) {
             links[i].onclick = function() {storeWindowTree(); return true;};
         } else {
-            //the function wrapper is important
-            //otherwise the last onclick handler would be assigned
-            //to oldonclick
+            //the function wrapper is important otherwise the
+            //last onclick handler would be assigned to oldonclick
             (function storeEvent() {
                 var oldonclick = links[i].onclick;
                 links[i].onclick = function(evt) {
@@ -95,11 +94,26 @@ function applyOnClick() {
 }
 
 function assertWindowId() {
-    var freshWindow = window.name.length < 1;
-    if (freshWindow) {
-        var url = urlWithoutWindowId(window.location.href);
-        window.name = "window";
-        window.location = url;
+    var url = window.location.href;
+    var vars = url.split(/&|\?/g);
+    var newUrl = "";
+    var iParam = 0;
+    for (var i=0; vars != null && i < vars.length; i++) {
+        var pair = vars[i].split("=");
+        if (pair.length == 1) {
+            newUrl = pair[0];
+        } else {
+            if (pair[0] == "windowId") { //
+                pair[1] = window.name ? window.name : "";
+            }
+            var amp = iParam++ > 0 ? "&" : "?";
+            newUrl =  newUrl + amp + pair[0] + "=" + pair[1];
+        }
+    }
+
+    if (newUrl != window.location.href) {
+        window.name = "tempWindowId";
+        window.location = newUrl;
     }
 }
 
@@ -112,7 +126,7 @@ window.onload = function(evt) {
         if (isHtml5()) {
             applyOnClick();
         }
-        // this ensures that even without the ClientSideWindowHandler
+        // this ensures that even without the ClientSideWindowHandler a new windowId gets issued on a new tab
         assertWindowId();
     }
 }

Modified: myfaces/extensions/cdi/trunk/jee-modules/jsf-module/impl/src/main/resources/static/windowhandler.html
URL: http://svn.apache.org/viewvc/myfaces/extensions/cdi/trunk/jee-modules/jsf-module/impl/src/main/resources/static/windowhandler.html?rev=1338175&r1=1338174&r2=1338175&view=diff
==============================================================================
--- myfaces/extensions/cdi/trunk/jee-modules/jsf-module/impl/src/main/resources/static/windowhandler.html (original)
+++ myfaces/extensions/cdi/trunk/jee-modules/jsf-module/impl/src/main/resources/static/windowhandler.html Mon May 14 12:15:25 2012
@@ -29,16 +29,11 @@
 
 <script type="text/javascript" >
 function isHtml5() {
-    try {
-        return !!localStorage.getItem;
-    } catch(e) {
-        return false;
-    }
+    try { return !!localStorage.getItem;
+    } catch(e) { return false; }
 }
 function unstringify(serialized) {
-    if (JSON) {
-        return JSON.parse(serialized);
-    }
+    if (JSON) { return JSON.parse(serialized); }
     return serialized.split("|||");
 }
 function getOldBody() {
@@ -78,7 +73,6 @@ function loadCss(clean) {
             localStorage.removeItem(window.name + '_css');
         }
     }
-
 }
 
 function replaceContent() {
@@ -120,8 +114,7 @@ function setUrlParam(baseUrl, paramName,
         var pair = vars[i].split("=");
         if (pair.length == 1) {
             newQuery = pair[0];
-        }
-        else {
+        } else {
             if (pair[0] != paramName) {
                 var amp = iParam++ > 0 ? "&" : "?";
                 newQuery =  newQuery + amp + pair[0] + "=" + pair[1];
@@ -132,7 +125,6 @@ function setUrlParam(baseUrl, paramName,
             }
         }
     }
-
     if (!paramFound) {
         var amp = iParam++ > 0 ? "&" : "?";
         newQuery =  newQuery + amp + paramName + "=" + paramValue;
@@ -149,7 +141,7 @@ window.onload = function() {
     if (windowId == 'uninitializedWindowId') {
         windowId = window.name
     }
-    if (!windowId || windowId.length < 3) {
+    if (!windowId || windowId.length < 1) {
         // request a new windowId
         windowId = 'automatedEntryPoint';
     }