struts-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From musa...@apache.org
Subject svn commit: r658883 - in /struts/struts2/trunk/core/src/main/java/org/apache/struts2: dispatcher/ServletDispatcherResult.java views/util/UrlHelper.java
Date Wed, 21 May 2008 21:31:05 GMT
Author: musachy
Date: Wed May 21 14:31:04 2008
New Revision: 658883

URL: http://svn.apache.org/viewvc?rev=658883&view=rev
Log:
WW-2120  Dispatcher does not put request parameters of new url on the value stack.

Modified:
    struts/struts2/trunk/core/src/main/java/org/apache/struts2/dispatcher/ServletDispatcherResult.java
    struts/struts2/trunk/core/src/main/java/org/apache/struts2/views/util/UrlHelper.java

Modified: struts/struts2/trunk/core/src/main/java/org/apache/struts2/dispatcher/ServletDispatcherResult.java
URL: http://svn.apache.org/viewvc/struts/struts2/trunk/core/src/main/java/org/apache/struts2/dispatcher/ServletDispatcherResult.java?rev=658883&r1=658882&r2=658883&view=diff
==============================================================================
--- struts/struts2/trunk/core/src/main/java/org/apache/struts2/dispatcher/ServletDispatcherResult.java
(original)
+++ struts/struts2/trunk/core/src/main/java/org/apache/struts2/dispatcher/ServletDispatcherResult.java
Wed May 21 14:31:04 2008
@@ -21,12 +21,15 @@
 
 package org.apache.struts2.dispatcher;
 
+import java.util.Map;
+
 import javax.servlet.RequestDispatcher;
 import javax.servlet.http.HttpServletRequest;
 import javax.servlet.http.HttpServletResponse;
 import javax.servlet.jsp.PageContext;
 
 import org.apache.struts2.ServletActionContext;
+import org.apache.struts2.views.util.UrlHelper;
 
 import com.opensymphony.xwork2.ActionInvocation;
 import com.opensymphony.xwork2.util.logging.Logger;
@@ -123,6 +126,17 @@
             HttpServletResponse response = ServletActionContext.getResponse();
             RequestDispatcher dispatcher = request.getRequestDispatcher(finalLocation);
 
+            //add parameters passed on the location to #parameters
+            // see WW-2120
+            if (invocation != null && finalLocation != null && finalLocation.length()
> 0
+                    && finalLocation.indexOf("?") > 0) {
+                String queryString = finalLocation.substring(finalLocation.indexOf("?") +
1);
+                Map parameters = (Map) invocation.getInvocationContext().getContextMap().get("parameters");
+                Map queryParams = UrlHelper.parseQueryString(queryString, true);
+                if (queryParams != null && !queryParams.isEmpty())
+                    parameters.putAll(queryParams);
+            }
+
             // if the view doesn't exist, let's do a 404
             if (dispatcher == null) {
                 response.sendError(404, "result '" + finalLocation + "' not found");

Modified: struts/struts2/trunk/core/src/main/java/org/apache/struts2/views/util/UrlHelper.java
URL: http://svn.apache.org/viewvc/struts/struts2/trunk/core/src/main/java/org/apache/struts2/views/util/UrlHelper.java?rev=658883&r1=658882&r2=658883&view=diff
==============================================================================
--- struts/struts2/trunk/core/src/main/java/org/apache/struts2/views/util/UrlHelper.java (original)
+++ struts/struts2/trunk/core/src/main/java/org/apache/struts2/views/util/UrlHelper.java Wed
May 21 14:31:04 2008
@@ -75,12 +75,12 @@
     public static String buildUrl(String action, HttpServletRequest request, HttpServletResponse
response, Map params, String scheme, boolean includeContext, boolean encodeResult, boolean
forceAddSchemeHostAndPort) {
     	return buildUrl(action, request, response, params, scheme, includeContext, encodeResult,
forceAddSchemeHostAndPort, true);
     }
-    
+
     public static String buildUrl(String action, HttpServletRequest request, HttpServletResponse
response, Map params, String scheme, boolean includeContext, boolean encodeResult, boolean
forceAddSchemeHostAndPort, boolean escapeAmp) {
         StringBuffer link = new StringBuffer();
 
         boolean changedScheme = false;
-        
+
         // FIXME: temporary hack until class is made a properly injected bean
         Container cont = ActionContext.getContext().getContainer();
         int httpPort = Integer.parseInt(cont.getInstance(String.class, StrutsConstants.STRUTS_URL_HTTP_PORT));
@@ -173,13 +173,13 @@
             buildParametersString(params, link);
         } else {
             buildParametersString(params, link, "&");
-        } 
+        }
 
         String result = link.toString();
-        
+
         while (result.indexOf("<script>") > 0){
         	result = result.replaceAll("<script>", "script");
-        }        
+        }
         try {
             result = encodeResult ? response.encodeURL(result) : result;
         } catch (Exception ex) {
@@ -236,23 +236,23 @@
                 } else {
                     link.append(buildParameterSubstring(name, value.toString()));
                 }
-                
+
                 if (iter.hasNext())
                     link.append(paramSeparator);
             }
         }
     }
 
-    
+
     private static String buildParameterSubstring(String name, String value) {
         StringBuilder builder = new StringBuilder();
         builder.append(name);
         builder.append('=');
         builder.append(translateAndEncode(value));
-        
+
         return builder.toString();
     }
-    
+
     /**
      * Translates any script expressions using {@link com.opensymphony.xwork2.util.TextParseUtil#translateVariables}
and
      * encodes the URL using {@link java.net.URLEncoder#encode} with the encoding specified
in the configuration.
@@ -292,11 +292,11 @@
 
     private static String getEncodingFromConfiguration() {
         final String encoding;
-        
+
         // FIXME: temporary hack until class is made a properly injected bean
         Container cont = ActionContext.getContext().getContainer();
         String customEncoding = cont.getInstance(String.class, StrutsConstants.STRUTS_I18N_ENCODING);
-        
+
         if (customEncoding != null) {
             encoding = customEncoding;
         } else {
@@ -306,6 +306,10 @@
     }
 
     public static Map parseQueryString(String queryString) {
+        return parseQueryString(queryString, false);
+    }
+
+    public static Map parseQueryString(String queryString, boolean forceValueArray) {
         Map queryParams = new LinkedHashMap();
         if (queryString != null) {
             String[] params = queryString.split("&");
@@ -323,7 +327,7 @@
                     if (paramName != null) {
                         String translatedParamValue = translateAndDecode(paramValue);
 
-                        if(queryParams.containsKey(paramName)) {
+                        if(queryParams.containsKey(paramName) || forceValueArray) {
                             // WW-1619 append new param value to existing value(s)
                             Object currentParam = queryParams.get(paramName);
                             if(currentParam instanceof String) {
@@ -331,13 +335,17 @@
                                         (String) currentParam, translatedParamValue});
                             } else {
                                 String currentParamValues[] = (String[]) currentParam;
-                                List paramList = new ArrayList(Arrays
-                                    .asList(currentParamValues));
-                                paramList.add(translatedParamValue);
-                                String newParamValues[] = new String[paramList
-                                    .size()];
-                                queryParams.put(paramName, paramList
-                                    .toArray(newParamValues));
+                                if (currentParamValues != null) {
+                                    List paramList = new ArrayList(Arrays
+                                        .asList(currentParamValues));
+                                    paramList.add(translatedParamValue);
+                                    String newParamValues[] = new String[paramList
+                                        .size()];
+                                    queryParams.put(paramName, paramList
+                                        .toArray(newParamValues));
+                                } else {
+                                    queryParams.put(paramName, new String[] {translatedParamValue});
+                                }
                             }
                         } else {
                             queryParams.put(paramName, translatedParamValue);



Mime
View raw message