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 fixed unit tests and initial redirect
Date Wed, 22 Jan 2014 20:14:00 GMT
Updated Branches:
  refs/heads/master 65d3d9d0c -> 9166490a5


DELTASPIKE-502 fixed unit tests and initial redirect

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

Branch: refs/heads/master
Commit: 9166490a55c74d4aa371080c85647420172f9f1a
Parents: 65d3d9d
Author: tandraschko <tandraschko@apache.org>
Authored: Wed Jan 22 21:13:50 2014 +0100
Committer: tandraschko <tandraschko@apache.org>
Committed: Wed Jan 22 21:13:50 2014 +0100

----------------------------------------------------------------------
 .../impl/scope/window/DefaultClientWindow.java  | 91 +++++++++++---------
 .../jsf/impl/util/ClientWindowHelper.java       | 36 ++++----
 .../deltaspike/jsf/impl/util/JsfUtils.java      |  5 ++
 .../jsf/impl/config/TestJsfModuleConfig.java    |  3 +-
 4 files changed, 76 insertions(+), 59 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/deltaspike/blob/9166490a/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 1bad3f0..531a2dc 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
@@ -90,6 +90,8 @@ public class DefaultClientWindow implements ClientWindow
      */
     private static final String DEFAULT_WINDOW_ID = "default";
 
+    private static final String WINDOW_ID_REQUEST_MAP_KEY =
+            ClientWindow.class.getName() + ".WindowId";
 
     @Inject
     private ClientWindowConfig clientWindowConfig;
@@ -104,23 +106,29 @@ public class DefaultClientWindow implements ClientWindow
     @Override
     public String getWindowId(FacesContext facesContext)
     {
+        ExternalContext externalContext = facesContext.getExternalContext();
+        Map<String, Object> requestMap = externalContext.getRequestMap();
+        
+        // try to lookup from cache
+        String windowId = (String) requestMap.get(WINDOW_ID_REQUEST_MAP_KEY);
+        if (windowId != null)
+        {
+            return windowId;
+        }
+        
         ClientWindowRenderMode clientWindowRenderMode = clientWindowConfig.getClientWindowRenderMode(facesContext);
         if (ClientWindowRenderMode.NONE.equals(clientWindowRenderMode))
         {
             // if this request should not get any window detection then we are done
-            return DEFAULT_WINDOW_ID;
+            windowId = DEFAULT_WINDOW_ID;
         }
-
-        if (ClientWindowRenderMode.DELEGATED.equals(clientWindowRenderMode))
+        else if (ClientWindowRenderMode.DELEGATED.equals(clientWindowRenderMode))
         {
-            return ClientWindowAdapter.getWindowIdFromJsf(facesContext);
+            windowId = ClientWindowAdapter.getWindowIdFromJsf(facesContext);
         }
-
-        if (ClientWindowRenderMode.LAZY.equals(clientWindowRenderMode))
+        else if (ClientWindowRenderMode.LAZY.equals(clientWindowRenderMode))
         {
-            ExternalContext externalContext = facesContext.getExternalContext();
-
-            String windowId = ClientWindowHelper.getInitialRedirectWindowId(facesContext);
+            windowId = ClientWindowHelper.getInitialRedirectWindowId(facesContext);
 
             if (StringUtils.isEmpty(windowId))
             {
@@ -133,51 +141,54 @@ public class DefaultClientWindow implements ClientWindow
                 {
                     ClientWindowHelper.handleInitialRedirect(facesContext, generateNewWindowId());
                     facesContext.responseComplete();
-                    return null;
+                    windowId = null;
                 }
                 else
                 {
-                    return generateNewWindowId();
+                    windowId = generateNewWindowId();
                 }
             }
-
-            return windowId;
-        }
-
-        if (facesContext.isPostback())
-        {
-            return getPostBackWindowId(facesContext);
         }
-
-        ExternalContext externalContext = facesContext.getExternalContext();
-
-        // and now for the GET request stuff
-        if (isNoscriptRequest(externalContext))
+        else if (ClientWindowRenderMode.CLIENTWINDOW.equals(clientWindowRenderMode))
         {
-            // the client has JavaScript disabled
-            clientWindowConfig.setJavaScriptEnabled(false);
+            if (facesContext.isPostback())
+            {
+                windowId = getPostBackWindowId(facesContext);
+            }
+            else if (isNoscriptRequest(externalContext))
+            {
+                // the client has JavaScript disabled
+                clientWindowConfig.setJavaScriptEnabled(false);
 
-            return DEFAULT_WINDOW_ID;
-        }
+                windowId = DEFAULT_WINDOW_ID;
+            }
+            else
+            {
+                windowId = getVerifiedWindowIdFromCookie(externalContext);
 
-        String windowId = getVerifiedWindowIdFromCookie(externalContext);
+                boolean newWindowIdRequested = false;
+                if (AUTOMATED_ENTRY_POINT_PARAMETER_KEY.equals(windowId))
+                {
+                    // this is a marker for generating a new windowId
+                    windowId = generateNewWindowId();
+                    newWindowIdRequested = true;
+                }
 
-        boolean newWindowIdRequested = false;
-        if (AUTOMATED_ENTRY_POINT_PARAMETER_KEY.equals(windowId))
-        {
-            // this is a marker for generating a new windowId
-            windowId = generateNewWindowId();
-            newWindowIdRequested = true;
+                if (windowId == null || newWindowIdRequested)
+                {
+                    // GET request without windowId - send windowhandlerfilter.html to get
the windowId
+                    sendWindowHandlerHtml(externalContext, windowId);
+                    facesContext.responseComplete();
+                }
+            }
         }
 
-        if (windowId == null || newWindowIdRequested)
+        // we have a valid windowId - set it and continue with the request
+        if (windowId != null)
         {
-            // GET request without windowId - send windowhandlerfilter.html to get the windowId
-            sendWindowHandlerHtml(externalContext, windowId);
-            facesContext.responseComplete();
+            requestMap.put(WINDOW_ID_REQUEST_MAP_KEY, windowId);
         }
-
-        // we have a valid windowId - set it and continue with the request
+        
         return windowId;
     }
 

http://git-wip-us.apache.org/repos/asf/deltaspike/blob/9166490a/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 0c4c6ef..2426cb2 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
@@ -18,10 +18,11 @@
  */
 package org.apache.deltaspike.jsf.impl.util;
 
+import java.io.IOException;
 import java.util.Map;
 import java.util.Map.Entry;
 import javax.enterprise.inject.Typed;
-import javax.faces.component.UIViewRoot;
+import javax.faces.FacesException;
 import javax.faces.context.ExternalContext;
 import javax.faces.context.FacesContext;
 import org.apache.deltaspike.jsf.spi.scope.window.ClientWindow;
@@ -41,26 +42,27 @@ public abstract class ClientWindowHelper
     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
+        // #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
-        String viewId = facesContext.getApplication().getViewHandler().deriveViewId(
-                facesContext, externalContext.getRequestServletPath());
-
-        // The NavigationHandler tries to access the UIViewRoot but it isn't available because
our
-        // ClientWindow will be initialized before the normal JSF lifecycle
-        UIViewRoot viewRoot = new UIViewRoot();
-        viewRoot.setViewId(viewId);
-        facesContext.setViewRoot(viewRoot);
-
-        String outcome = viewId + "?faces-redirect=true&includeViewParams=true";
-        // append it manually - includeViewParams doesn't work here because of the not fully
initialized UIViewRoot
-        outcome = JsfUtils.addRequestParameters(externalContext, outcome, true);
-
-        facesContext.getApplication().getNavigationHandler().handleNavigation(facesContext,
null, outcome);
+        String url = externalContext.getRequestScheme()
+                + "://" + externalContext.getRequestServerName()
+                + ":" + externalContext.getRequestServerPort()
+                + externalContext.getRequestContextPath()
+                + externalContext.getRequestServletPath();
+ 
+        url = JsfUtils.addRequestParameters(externalContext, url, true);
+        
+        try
+        {
+            externalContext.redirect(url);
+        }
+        catch (IOException e)
+        {
+            throw new FacesException("Could not send initial redirect!", e);
+        }
     }
 
     public static boolean isInitialRedirect(FacesContext facesContext)

http://git-wip-us.apache.org/repos/asf/deltaspike/blob/9166490a/deltaspike/modules/jsf/impl/src/main/java/org/apache/deltaspike/jsf/impl/util/JsfUtils.java
----------------------------------------------------------------------
diff --git a/deltaspike/modules/jsf/impl/src/main/java/org/apache/deltaspike/jsf/impl/util/JsfUtils.java
b/deltaspike/modules/jsf/impl/src/main/java/org/apache/deltaspike/jsf/impl/util/JsfUtils.java
index f5aea23..5252d7e 100644
--- a/deltaspike/modules/jsf/impl/src/main/java/org/apache/deltaspike/jsf/impl/util/JsfUtils.java
+++ b/deltaspike/modules/jsf/impl/src/main/java/org/apache/deltaspike/jsf/impl/util/JsfUtils.java
@@ -179,6 +179,11 @@ public abstract class JsfUtils
      */
     public static String addRequestParameters(ExternalContext externalContext, String url,
boolean encodeValues)
     {
+        if (externalContext.getRequestParameterValuesMap().isEmpty())
+        {
+            return url;
+        }
+        
         StringBuilder finalUrl = new StringBuilder(url);
         boolean existingParameters = url.contains("?");
 

http://git-wip-us.apache.org/repos/asf/deltaspike/blob/9166490a/deltaspike/modules/jsf/impl/src/test/java/org/apache/deltaspike/test/jsf/impl/config/TestJsfModuleConfig.java
----------------------------------------------------------------------
diff --git a/deltaspike/modules/jsf/impl/src/test/java/org/apache/deltaspike/test/jsf/impl/config/TestJsfModuleConfig.java
b/deltaspike/modules/jsf/impl/src/test/java/org/apache/deltaspike/test/jsf/impl/config/TestJsfModuleConfig.java
index 4775814..f8be4e5 100644
--- a/deltaspike/modules/jsf/impl/src/test/java/org/apache/deltaspike/test/jsf/impl/config/TestJsfModuleConfig.java
+++ b/deltaspike/modules/jsf/impl/src/test/java/org/apache/deltaspike/test/jsf/impl/config/TestJsfModuleConfig.java
@@ -33,7 +33,6 @@ public class TestJsfModuleConfig extends JsfModuleConfig
     @Override
     public ClientWindowConfig.ClientWindowRenderMode getDefaultWindowMode()
     {
-        //TODO check issue with LAZY
-        return ClientWindowConfig.ClientWindowRenderMode.CLIENTWINDOW;
+        return ClientWindowConfig.ClientWindowRenderMode.LAZY;
     }
 }


Mime
View raw message