DELTASPIKE-454 refactored initial redirect Project: http://git-wip-us.apache.org/repos/asf/deltaspike/repo Commit: http://git-wip-us.apache.org/repos/asf/deltaspike/commit/9133bc44 Tree: http://git-wip-us.apache.org/repos/asf/deltaspike/tree/9133bc44 Diff: http://git-wip-us.apache.org/repos/asf/deltaspike/diff/9133bc44
Branch: refs/heads/master Commit: 9133bc44b7be3e45e0b366e961c841547692caa9 Parents: 41d31e8 Author: andraschko <[email protected]> Authored: Thu Jan 9 11:48:34 2014 +0100 Committer: andraschko <[email protected]> Committed: Thu Jan 9 11:48:34 2014 +0100 ---------------------------------------------------------------------- .../DeltaSpikeExternalContextWrapper.java | 10 +++++++--- .../impl/scope/window/DefaultClientWindow.java | 9 ++------- .../jsf/impl/util/ClientWindowHelper.java | 20 +++++++++++++++++++- 3 files changed, 28 insertions(+), 11 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/deltaspike/blob/9133bc44/deltaspike/modules/jsf/impl/src/main/java/org/apache/deltaspike/jsf/impl/listener/request/DeltaSpikeExternalContextWrapper.java ---------------------------------------------------------------------- diff --git a/deltaspike/modules/jsf/impl/src/main/java/org/apache/deltaspike/jsf/impl/listener/request/DeltaSpikeExternalContextWrapper.java b/deltaspike/modules/jsf/impl/src/main/java/org/apache/deltaspike/jsf/impl/listener/request/DeltaSpikeExternalContextWrapper.java index bf99621..d5e039b 100644 --- a/deltaspike/modules/jsf/impl/src/main/java/org/apache/deltaspike/jsf/impl/listener/request/DeltaSpikeExternalContextWrapper.java +++ b/deltaspike/modules/jsf/impl/src/main/java/org/apache/deltaspike/jsf/impl/listener/request/DeltaSpikeExternalContextWrapper.java @@ -42,10 +42,14 @@ public class DeltaSpikeExternalContextWrapper extends ExternalContextWrapper imp @Override public void redirect(String url) throws IOException { - JsfUtils.saveFacesMessages(this.wrapped); + FacesContext facesContext = FacesContext.getCurrentInstance(); - String targetURL = ClientWindowHelper.appendWindowId(FacesContext.getCurrentInstance(), - url, this.clientWindow); + if (!ClientWindowHelper.isInitialRedirect(facesContext)) + { + JsfUtils.saveFacesMessages(this.wrapped); + } + + String targetURL = ClientWindowHelper.appendWindowId(facesContext, url, this.clientWindow); this.wrapped.redirect(targetURL); } http://git-wip-us.apache.org/repos/asf/deltaspike/blob/9133bc44/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 e26574e..9f6762d 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 @@ -82,8 +82,6 @@ public class DefaultClientWindow extends ClientWindow private static final String WINDOW_ID_REPLACE_PATTERN = "$$windowIdValue$$"; private static final String NOSCRIPT_URL_REPLACE_PATTERN = "$$noscriptUrl$$"; - private static final String NEW_WINDOW_ID = DefaultClientWindow.class.getName() + ".NEW_WINDOW_ID"; - /** * Use this parameter to force a 'direct' request from the clients without any windowId detection * We keep this name for backward compat with CODI. @@ -122,7 +120,7 @@ public class DefaultClientWindow extends ClientWindow { ExternalContext externalContext = facesContext.getExternalContext(); - String windowId = (String) facesContext.getAttributes().get(NEW_WINDOW_ID); + String windowId = (String) ClientWindowHelper.getInitialRedirectWindowId(facesContext); if (windowId == null) { @@ -131,10 +129,7 @@ public class DefaultClientWindow extends ClientWindow if (windowId == null) { - // store the new windowId as context attribute to prevent infinite loops - // the #sendRedirect will append the windowId (from #getWindowId again) to the redirectUrl - facesContext.getAttributes().put(NEW_WINDOW_ID, generateNewWindowId()); - ClientWindowHelper.handleInitialRedirect(facesContext); + ClientWindowHelper.handleInitialRedirect(facesContext, generateNewWindowId()); facesContext.responseComplete(); return null; } http://git-wip-us.apache.org/repos/asf/deltaspike/blob/9133bc44/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 a6c9b4c..0c4c6ef 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 @@ -29,13 +29,21 @@ import org.apache.deltaspike.jsf.spi.scope.window.ClientWindow; @Typed() public abstract class ClientWindowHelper { + public static final String INITIAL_REDIRECT_WINDOW_ID = ClientWindowHelper.class.getName() + + ".INITIAL_REDIRECT_WINDOW_ID"; + /** * Handles the initial redirect for the URL modus, if no windowId is available in the current request URL. * * @param facesContext the {@link FacesContext} + * @param newWindowId the new windowId */ - public static void handleInitialRedirect(FacesContext facesContext) + public static void handleInitialRedirect(FacesContext facesContext, String newWindowId) { + // store the new windowId as context attribute to prevent infinite loops + // the #sendRedirect will append the windowId (from ClientWindow#getWindowId again) to the redirectUrl + facesContext.getAttributes().put(INITIAL_REDIRECT_WINDOW_ID, newWindowId); + ExternalContext externalContext = facesContext.getExternalContext(); // send initial redirect to add the windowId to the current request URL @@ -55,6 +63,16 @@ public abstract class ClientWindowHelper facesContext.getApplication().getNavigationHandler().handleNavigation(facesContext, null, outcome); } + public static boolean isInitialRedirect(FacesContext facesContext) + { + return facesContext.getAttributes().containsKey(INITIAL_REDIRECT_WINDOW_ID); + } + + public static String getInitialRedirectWindowId(FacesContext facesContext) + { + return (String) facesContext.getAttributes().get(INITIAL_REDIRECT_WINDOW_ID); + } + /** * Appends the current windowId to the given url, if enabled via * {@link ClientWindow#isClientWindowRenderModeEnabled(javax.faces.context.FacesContext)}
