struts-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From cnenn...@apache.org
Subject struts git commit: WW-4631: unified behavior for empty url parameters
Date Fri, 23 Sep 2016 09:33:36 GMT
Repository: struts
Updated Branches:
  refs/heads/master 6916f47c9 -> e7ce5dcc0


WW-4631: unified behavior for empty url parameters


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

Branch: refs/heads/master
Commit: e7ce5dcc0dc576fe8081c66e17b57b30257af9f4
Parents: 6916f47
Author: cnenning <cnenning@apache.org>
Authored: Fri Sep 23 11:33:19 2016 +0200
Committer: cnenning <cnenning@apache.org>
Committed: Fri Sep 23 11:33:19 2016 +0200

----------------------------------------------------------------------
 .../org/apache/struts2/components/Param.java    | 16 ++--
 .../apache/struts2/views/jsp/URLTagTest.java    | 88 ++++++++++++++++----
 2 files changed, 82 insertions(+), 22 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/struts/blob/e7ce5dcc/core/src/main/java/org/apache/struts2/components/Param.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/struts2/components/Param.java b/core/src/main/java/org/apache/struts2/components/Param.java
index 2f7e6bd..acdbd26 100644
--- a/core/src/main/java/org/apache/struts2/components/Param.java
+++ b/core/src/main/java/org/apache/struts2/components/Param.java
@@ -50,7 +50,7 @@ import java.io.Writer;
  * <ul>
  *      <li>name (String) - the name of the parameter</li>
  *      <li>value (Object) - the value of the parameter</li>
- *      <li>suppressEmptyParameters (boolean) - whether to suppress empty parameters</li>
+ *      <li>suppressEmptyParameters (boolean) - whether to suppress this parameter
if empty</li>
  * </ul>
  * <!-- END SNIPPET: params -->
  * <p>
@@ -81,13 +81,11 @@ import java.io.Writer;
  * </p>
  *
  * <pre>
- * &lt;s:a action="eventAdd" accesskey="a"&gt;
- *   &lt;s:text name="title.heading.eventadd" /&gt;
+ * &lt;s:url action="eventAdd"&gt;
  *   &lt;s:param name="bean.searchString" value="%{bean.searchString}" /&gt;
  *   &lt;s:param name="bean.filter" value="%{bean.filter}" /&gt;
- *   &lt;s:param name="bean.pageNum" value="%{pager.pageNumber}" /&gt;
- *   &lt;s:param name="suppressEmptyParameters" value="true"/&gt;
- * &lt;/s:a&gt;
+ *   &lt;s:param name="bean.pageNum" value="%{pager.pageNumber}" suppressEmptyParameters="true"
/&gt;
+ * &lt;/s:url&gt;
  * </pre>
  * <!-- END SNIPPET: example -->
  * <p>
@@ -141,6 +139,8 @@ public class Param extends Component {
                     if (value != null && StringUtils.isNotBlank(value.toString()))
{
                         component.addParameter(name, value);
                     }
+                } else if (value == null || StringUtils.isBlank(value.toString())) {
+                    component.addParameter(name, "");
                 } else {
                     component.addParameter(name, value);
                 }
@@ -149,7 +149,9 @@ public class Param extends Component {
             if (component instanceof UnnamedParametric) {
                 ((UnnamedParametric) component).addParameter(body);
             } else {
-                component.addParameter(findString(name), body);
+                if (!(suppressEmptyParameters && StringUtils.isBlank(body))) {
+                    component.addParameter(findString(name), body);
+                }
             }
         }
 

http://git-wip-us.apache.org/repos/asf/struts/blob/e7ce5dcc/core/src/test/java/org/apache/struts2/views/jsp/URLTagTest.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/org/apache/struts2/views/jsp/URLTagTest.java b/core/src/test/java/org/apache/struts2/views/jsp/URLTagTest.java
index 627fdc4..37d4979 100644
--- a/core/src/test/java/org/apache/struts2/views/jsp/URLTagTest.java
+++ b/core/src/test/java/org/apache/struts2/views/jsp/URLTagTest.java
@@ -21,12 +21,17 @@
 
 package org.apache.struts2.views.jsp;
 
-import com.mockobjects.dynamic.Mock;
-import com.opensymphony.xwork2.ActionContext;
-import com.opensymphony.xwork2.ActionProxy;
-import com.opensymphony.xwork2.DefaultActionInvocation;
-import com.opensymphony.xwork2.DefaultActionProxyFactory;
-import com.opensymphony.xwork2.inject.Container;
+import java.io.File;
+import java.io.StringWriter;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.LinkedHashMap;
+import java.util.List;
+import java.util.Map;
+
+import javax.servlet.http.HttpSession;
+import javax.servlet.jsp.JspWriter;
+
 import org.apache.struts2.ServletActionContext;
 import org.apache.struts2.components.URL;
 import org.apache.struts2.dispatcher.ApplicationMap;
@@ -37,15 +42,13 @@ import org.apache.struts2.dispatcher.SessionMap;
 import org.apache.struts2.dispatcher.mapper.ActionMapping;
 import org.apache.struts2.dispatcher.mapper.DefaultActionMapper;
 
-import javax.servlet.http.HttpSession;
-import javax.servlet.jsp.JspWriter;
-import java.io.File;
-import java.io.StringWriter;
-import java.util.ArrayList;
-import java.util.HashMap;
-import java.util.LinkedHashMap;
-import java.util.List;
-import java.util.Map;
+import com.mockobjects.dynamic.Mock;
+import com.mockobjects.servlet.MockBodyContent;
+import com.opensymphony.xwork2.ActionContext;
+import com.opensymphony.xwork2.ActionProxy;
+import com.opensymphony.xwork2.DefaultActionInvocation;
+import com.opensymphony.xwork2.DefaultActionProxyFactory;
+import com.opensymphony.xwork2.inject.Container;
 
 /**
  * Unit test for {@link URLTag}.
@@ -675,6 +678,61 @@ public class URLTagTest extends AbstractUITagTest {
 		);
 	}
 
+    public void testIncludeEmptyParameters() throws Exception {
+        request.setRequestURI("/public/about");
+
+        tag.setAction("company");
+        tag.setEscapeAmp("false");
+
+        tag.doStartTag();
+
+        ParamTag param1 = new ParamTag();
+        param1.setPageContext(pageContext);
+        param1.setName("paraWithSetValue");
+        param1.setValue("");
+        param1.setSuppressEmptyParameters(false);
+        param1.doStartTag();
+        param1.doEndTag();
+
+        ParamTag param2 = new ParamTag();
+        param2.setPageContext(pageContext);
+        param2.setName("paraWithSetBody");
+        param2.setBodyContent(new MockBodyContent() {
+            @Override
+            public String getString() {
+                return "";
+            }
+        });
+        param2.setSuppressEmptyParameters(false);
+        param2.doStartTag();
+        param2.doEndTag();
+
+        ParamTag param3 = new ParamTag();
+        param3.setPageContext(pageContext);
+        param3.setName("paraWithSetValueSurpressed");
+        param3.setValue("");
+        param3.setSuppressEmptyParameters(true);
+        param3.doStartTag();
+        param3.doEndTag();
+
+        ParamTag param4 = new ParamTag();
+        param4.setPageContext(pageContext);
+        param4.setName("paraWithSetBodySurpressed");
+        param4.setBodyContent(new MockBodyContent() {
+            @Override
+            public String getString() {
+                return "";
+            }
+        });
+        param4.setSuppressEmptyParameters(true);
+        param4.doStartTag();
+        param4.doEndTag();
+
+        tag.doEndTag();
+
+        assertEquals("/company.action?paraWithSetValue=&paraWithSetBody=", writer.toString());
+    }
+
     protected void setUp() throws Exception {
         super.setUp();
 


Mime
View raw message