Repository: deltaspike Updated Branches: refs/heads/master f6353412d -> a16d304e6
DELTASPIKE-932 only render deltaspikeInitialRedirectWindowId in LAZY mode Project: http://git-wip-us.apache.org/repos/asf/deltaspike/repo Commit: http://git-wip-us.apache.org/repos/asf/deltaspike/commit/a16d304e Tree: http://git-wip-us.apache.org/repos/asf/deltaspike/tree/a16d304e Diff: http://git-wip-us.apache.org/repos/asf/deltaspike/diff/a16d304e Branch: refs/heads/master Commit: a16d304e67c26304807763aa4c95e8c0cbb83abc Parents: f635341 Author: Thomas Andraschko <[email protected]> Authored: Tue Jun 30 22:45:11 2015 +0200 Committer: Thomas Andraschko <[email protected]> Committed: Tue Jun 30 22:46:11 2015 +0200 ---------------------------------------------------------------------- .../jsf/spi/scope/window/ClientWindow.java | 5 ++ .../component/window/WindowIdHtmlRenderer.java | 58 ++++++++------------ .../impl/scope/window/DefaultClientWindow.java | 6 ++ .../strategy/AbstractClientWindowStrategy.java | 6 ++ .../window/strategy/LazyWindowStrategy.java | 18 ++++-- 5 files changed, 52 insertions(+), 41 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/deltaspike/blob/a16d304e/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 8397c23..db15095 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 @@ -71,4 +71,9 @@ public interface ClientWindow * @return meta-data for the current window which should get added to URLs, null otherwise */ Map<String, String> getQueryURLParameters(FacesContext facesContext); + + /** + * @return true if the implementation possible sends an initial redirect. + */ + boolean isInitialRedirectSupported(FacesContext facesContext); } http://git-wip-us.apache.org/repos/asf/deltaspike/blob/a16d304e/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 ad992e9..6b9ce31 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 @@ -30,8 +30,8 @@ import javax.servlet.http.Cookie; import javax.servlet.http.HttpServletResponse; import org.apache.deltaspike.core.api.provider.BeanProvider; -import org.apache.deltaspike.core.spi.scope.window.WindowContext; 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; @FacesRenderer(componentFamily = WindowIdComponent.COMPONENT_FAMILY, rendererType = WindowIdComponent.COMPONENT_TYPE) @@ -40,7 +40,7 @@ import org.apache.deltaspike.jsf.spi.scope.window.ClientWindowConfig; @ResourceDependency(library = "javax.faces", name = "jsf.js", target = "head") } ) public class WindowIdHtmlRenderer extends Renderer { - private volatile WindowContext windowContext; + private volatile ClientWindow clientWindow; private volatile ClientWindowConfig clientWindowConfig; private int maxWindowIdCount = 10; @@ -57,7 +57,10 @@ public class WindowIdHtmlRenderer extends Renderer { super.encodeBegin(context, component); - String windowId = getWindowContext().getCurrentWindowId(); + lazyInit(); + + String windowId = clientWindow.getWindowId(context); + String clientWindowRenderMode = clientWindowConfig.getClientWindowRenderMode(context).name(); //already ensured by DefaultClientWindow //just to ensure that we don't get a security issue in case of a customized client-window implementation @@ -67,59 +70,44 @@ public class WindowIdHtmlRenderer extends Renderer windowId = windowId.substring(0, this.maxWindowIdCount); } - String mode = getClientWindowConfig().getClientWindowRenderMode(context).name(); - ResponseWriter writer = context.getResponseWriter(); writer.startElement("script", component); writer.writeAttribute("type", "text/javascript", null); writer.write("window.deltaspikeWindowId='" + windowId + "';"); - writer.write("window.deltaspikeClientWindowRenderMode='" + mode + "';"); + writer.write("window.deltaspikeClientWindowRenderMode='" + clientWindowRenderMode + "';"); // see #729 - Object cookie = ClientWindowHelper.getRequestWindowIdCookie(context, windowId); - if (cookie != null && cookie instanceof Cookie) + if (clientWindow.isInitialRedirectSupported(context)) { - Cookie servletCookie = (Cookie) cookie; - writer.write("window.deltaspikeInitialRedirectWindowId='" + servletCookie.getValue() + "';"); - - // expire/remove cookie - servletCookie.setMaxAge(0); - ((HttpServletResponse) context.getExternalContext().getResponse()).addCookie(servletCookie); + Object cookie = ClientWindowHelper.getRequestWindowIdCookie(context, windowId); + if (cookie != null && cookie instanceof Cookie) + { + Cookie servletCookie = (Cookie) cookie; + writer.write("window.deltaspikeInitialRedirectWindowId='" + servletCookie.getValue() + "';"); + + // expire/remove cookie + servletCookie.setMaxAge(0); + ((HttpServletResponse) context.getExternalContext().getResponse()).addCookie(servletCookie); + } } writer.endElement("script"); } - private WindowContext getWindowContext() + private void lazyInit() { - if (windowContext == null) + if (clientWindow == null) { synchronized (this) { - if (windowContext == null) + if (clientWindow == null) { - windowContext = BeanProvider.getContextualReference(WindowContext.class); + clientWindowConfig = BeanProvider.getContextualReference(ClientWindowConfig.class); + clientWindow = BeanProvider.getContextualReference(ClientWindow.class); maxWindowIdCount = ClientWindowHelper.getMaxWindowIdLength(); } } } - - 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/a16d304e/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 2db4b7e..b517af9 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 @@ -87,6 +87,12 @@ public class DefaultClientWindow implements ClientWindow { return getClientWindow(facesContext).getQueryURLParameters(facesContext); } + + @Override + public boolean isInitialRedirectSupported(FacesContext facesContext) + { + return getClientWindow(facesContext).isInitialRedirectSupported(facesContext); + } protected ClientWindow getClientWindow(FacesContext facesContext) { http://git-wip-us.apache.org/repos/asf/deltaspike/blob/a16d304e/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 7009dd4..af956a2 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 @@ -174,6 +174,12 @@ public abstract class AbstractClientWindowStrategy implements ClientWindow } @Override + public boolean isInitialRedirectSupported(FacesContext facesContext) + { + return false; + } + + @Override public Map<String, String> getQueryURLParameters(FacesContext facesContext) { Map<String, String> cachedParameters = http://git-wip-us.apache.org/repos/asf/deltaspike/blob/a16d304e/deltaspike/modules/jsf/impl/src/main/java/org/apache/deltaspike/jsf/impl/scope/window/strategy/LazyWindowStrategy.java ---------------------------------------------------------------------- diff --git a/deltaspike/modules/jsf/impl/src/main/java/org/apache/deltaspike/jsf/impl/scope/window/strategy/LazyWindowStrategy.java b/deltaspike/modules/jsf/impl/src/main/java/org/apache/deltaspike/jsf/impl/scope/window/strategy/LazyWindowStrategy.java index 794a1bc..6121628 100644 --- a/deltaspike/modules/jsf/impl/src/main/java/org/apache/deltaspike/jsf/impl/scope/window/strategy/LazyWindowStrategy.java +++ b/deltaspike/modules/jsf/impl/src/main/java/org/apache/deltaspike/jsf/impl/scope/window/strategy/LazyWindowStrategy.java @@ -66,12 +66,6 @@ public class LazyWindowStrategy extends AbstractClientWindowStrategy } @Override - protected boolean isSupportClientWindowRenderingMode() - { - return true; - } - - @Override protected Map<String, String> createQueryURLParameters(FacesContext facesContext) { String windowId = getWindowId(facesContext); @@ -85,4 +79,16 @@ public class LazyWindowStrategy extends AbstractClientWindowStrategy parameters.put(ClientWindowHelper.RequestParameters.GET_WINDOW_ID, windowId); return parameters; } + + @Override + protected boolean isSupportClientWindowRenderingMode() + { + return true; + } + + @Override + public boolean isInitialRedirectSupported(FacesContext facesContext) + { + return true; + } }
