Repository: deltaspike Updated Branches: refs/heads/master 3b355587a -> 97cc3e300
DELTASPIKE-968 implemented storeWindowTree for buttons and ajax requests Project: http://git-wip-us.apache.org/repos/asf/deltaspike/repo Commit: http://git-wip-us.apache.org/repos/asf/deltaspike/commit/97cc3e30 Tree: http://git-wip-us.apache.org/repos/asf/deltaspike/tree/97cc3e30 Diff: http://git-wip-us.apache.org/repos/asf/deltaspike/diff/97cc3e30 Branch: refs/heads/master Commit: 97cc3e30067e46df16e79fdb7383c1ea0b2d41bd Parents: 3b35558 Author: Thomas Andraschko <[email protected]> Authored: Sat Aug 8 14:27:34 2015 +0200 Committer: Thomas Andraschko <[email protected]> Committed: Sat Aug 8 14:27:34 2015 +0200 ---------------------------------------------------------------------- .../spi/scope/window/ClientWindowConfig.java | 25 +++++++-- .../scope/window/DefaultClientWindowConfig.java | 16 +++++- .../component/window/WindowIdHtmlRenderer.java | 9 ++- .../resources/deltaspike/windowhandler.js | 58 +++++++++++++++++++- 4 files changed, 97 insertions(+), 11 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/deltaspike/blob/97cc3e30/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 11ea056..65ef633 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 @@ -88,14 +88,31 @@ public interface ClientWindowConfig extends Serializable String getClientWindowHtml(); /** - * @return whether localStorage is used in the browser to store the HTML content between client redirects. - * Currently it's only used by {@link ClientWindowRenderMode#CLIENTWINDOW}. + * @return Whether the DOM tree should stored in the localStorage for the windowhandler.html + * when clicking on a link. + * Currently it's only used by {@link ClientWindowRenderMode#CLIENTWINDOW}. * @see windowhandler.html */ - boolean isClientWindowStoreWindowTreeEnabled(); + boolean isClientWindowStoreWindowTreeEnabledOnLinkClick(); - boolean isClientWindowTokenizedRedirectEnabled(); + /** + * @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 + */ + boolean isClientWindowStoreWindowTreeEnabledOnButtonClick(); + boolean isClientWindowTokenizedRedirectEnabled(); + /** * Restricts the number of active windows. * http://git-wip-us.apache.org/repos/asf/deltaspike/blob/97cc3e30/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 67549f9..7232767 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 @@ -231,11 +231,23 @@ public class DefaultClientWindowConfig implements ClientWindowConfig } @Override - public boolean isClientWindowStoreWindowTreeEnabled() + public boolean isClientWindowStoreWindowTreeEnabledOnLinkClick() { return true; } - + + @Override + public boolean isClientWindowStoreWindowTreeEnabledOnAjaxRequest() + { + return false; + } + + @Override + public boolean isClientWindowStoreWindowTreeEnabledOnButtonClick() + { + return false; + } + @Override public boolean isClientWindowTokenizedRedirectEnabled() { http://git-wip-us.apache.org/repos/asf/deltaspike/blob/97cc3e30/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 59bdc0f..1858aac 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 @@ -77,8 +77,13 @@ public class WindowIdHtmlRenderer extends Renderer writer.write("(function(){"); writer.write("dswh.init('" + windowId + "','" + clientWindowRenderMode.name() + "',{"); - writer.write("'storeWindowTree':" + clientWindowConfig.isClientWindowStoreWindowTreeEnabled()); - writer.write(",'tokenizedRedirect':" + clientWindowConfig.isClientWindowTokenizedRedirectEnabled()); + writer.write("'tokenizedRedirect':" + clientWindowConfig.isClientWindowTokenizedRedirectEnabled()); + writer.write(",'storeWindowTreeOnLinkClick':" + + 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/97cc3e30/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 3e55f7e..2bcb89d 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 @@ -77,9 +77,26 @@ window.dswh = window.dswh || { }, init : function(ajax) { - this.overwriteOnClickEvents(); + this.overwriteLinkOnClickEvents(); + 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() { @@ -90,10 +107,10 @@ window.dswh = window.dswh || { } }, - overwriteOnClickEvents : function() { + overwriteLinkOnClickEvents : function() { var tokenizedRedirectEnabled = dswh.cfg.tokenizedRedirect; - var storeWindowTreeEnabled = dswh.utils.isHtml5() && dswh.cfg.storeWindowTree; + var storeWindowTreeEnabled = dswh.utils.isHtml5() && dswh.cfg.storeWindowTreeOnLinkClick; if (tokenizedRedirectEnabled || storeWindowTreeEnabled) { var links = document.getElementsByTagName("a"); @@ -143,6 +160,41 @@ window.dswh = window.dswh || { } } }, + + overwriteButtonOnClickEvents : function() { + + var storeWindowTreeEnabled = dswh.utils.isHtml5() && dswh.cfg.storeWindowTreeOnButtonClick; + + if (storeWindowTreeEnabled) { + var inputs = document.getElementsByTagName("input"); + for (var i = 0; i < inputs.length; i++) { + var input = inputs[i]; + if (input.getAttribute("type") === "submit" || input.getAttribute("type") === "button") { + if (!input.onclick) { + input.onclick = function() { + dswh.strategy.CLIENTWINDOW.storeWindowTree(); + return true; + }; + } else { + // prevent double decoration + if (!("" + input.onclick).match(".*storeWindowTree().*")) { + //the function wrapper is important otherwise the + //last onclick handler would be assigned to oldonclick + (function storeEvent() { + var oldonclick = input.onclick; + input.onclick = function(evt) { + //ie handling added + evt = evt || window.event; + + return dswh.strategy.CLIENTWINDOW.storeWindowTree() && oldonclick.bind(this)(evt); + }; + })(); + } + } + } + } + } + }, isHrefDefined : function(link) { // skip link without href
