Struts 2
  1. Struts 2
  2. WW-4088

Supressing empty parameters on <s:a> tag

    Details

    • Type: Improvement Improvement
    • Status: Closed
    • Priority: Minor Minor
    • Resolution: Fixed
    • Affects Version/s: 2.3.14.2
    • Fix Version/s: 2.3.16
    • Labels:
      None
    • Environment:

      Tomcat/Centos

      Description

      Hello,

      When using the s:a anchor tag you can get parameters with empty values ie ?foo= for null values.

      It would be good if there was a way to filter these out, similar to the struts.xml <param name="suppressEmptyParameters">true</param>. The <s:if> tags in the body are ignored. I either have to do it in programatically or use jstl

      ie possibly do something similar :

      from:

      <s:a action="eventAdd" accesskey="a">
      <s:text name="title.heading.eventadd" />
      <c:if test="${not empty bean.searchString}">
       <s:param name="bean.searchString" value="%{bean.searchString}" />
      </c:if>
      <c:if test="${not empty bean.filter}">
       <s:param name="bean.filter" value="%{bean.filter}" />
      </c:if>
      <s:param name="bean.pageNum" value="%{pager.pageNumber}" />
      </s:a>
      

      To:

      <s:a action="eventAdd" accesskey="a">
      <s:text name="title.heading.eventadd" />
      <s:param name="bean.searchString" value="%{bean.searchString}" />
      <s:param name="bean.filter" value="%{bean.filter}" />
      <s:param name="bean.pageNum" value="%{pager.pageNumber}" />
      <s:param name="suppressEmptyParameters" value="true"/>
      </s:a>
      

      (Ref WW-3920)

      Cheers Greg

      1. patch.txt
        7 kB
        Greg Huber
      2. patch.txt
        0.8 kB
        Greg Huber
      3. paramtag_patch.txt
        3 kB
        Greg Huber

        Issue Links

          Activity

          Hide
          Rene Gielen added a comment -

          Since empty parameters are absolutely valid, this should be a local setting to the param-Tag rather than some global setting or filter

          Show
          Rene Gielen added a comment - Since empty parameters are absolutely valid, this should be a local setting to the param-Tag rather than some global setting or filter
          Hide
          Rene Gielen added a comment - - edited

          Patches welcome

          Show
          Rene Gielen added a comment - - edited Patches welcome
          Hide
          Greg Huber added a comment - - edited

          Hello, here is my two penneth worth!
          Cheers Greg.

          Show
          Greg Huber added a comment - - edited Hello, here is my two penneth worth! Cheers Greg.
          Hide
          Greg Huber added a comment -

          better.....

          Show
          Greg Huber added a comment - better.....
          Hide
          Greg Huber added a comment -

          Same result but via modified param/paramtag.

          Show
          Greg Huber added a comment - Same result but via modified param/paramtag.
          Hide
          ASF subversion and git services added a comment -

          Commit 1533366 from Lukasz Lenart in branch 'struts2/trunk'
          [ https://svn.apache.org/r1533366 ]

          WW-4088 Defines new suppressEmptyParams flag

          Show
          ASF subversion and git services added a comment - Commit 1533366 from Lukasz Lenart in branch 'struts2/trunk' [ https://svn.apache.org/r1533366 ] WW-4088 Defines new suppressEmptyParams flag
          Hide
          Lukasz Lenart added a comment -

          Patch applied, thanks!

          Show
          Lukasz Lenart added a comment - Patch applied, thanks!
          Hide
          Hudson added a comment -

          SUCCESS: Integrated in Struts2-JDK6 #814 (See https://builds.apache.org/job/Struts2-JDK6/814/)
          WW-4088 Defines new suppressEmptyParams flag (lukaszlenart: rev 1533366)

          • /struts/struts2/trunk/core/src/main/java/org/apache/struts2/components/Param.java
          • /struts/struts2/trunk/core/src/main/java/org/apache/struts2/views/jsp/ParamTag.java
          • /struts/struts2/trunk/core/src/site/resources/tags/param.html
          Show
          Hudson added a comment - SUCCESS: Integrated in Struts2-JDK6 #814 (See https://builds.apache.org/job/Struts2-JDK6/814/ ) WW-4088 Defines new suppressEmptyParams flag (lukaszlenart: rev 1533366) /struts/struts2/trunk/core/src/main/java/org/apache/struts2/components/Param.java /struts/struts2/trunk/core/src/main/java/org/apache/struts2/views/jsp/ParamTag.java /struts/struts2/trunk/core/src/site/resources/tags/param.html
          Hide
          Greg Huber added a comment -

          Lukasz,

          Sorry, but I have noticed that my patch does not handle integers correctly, alas, we need to do another change

          It does kind of the same check, but this works with integers/doubles.

          <code>
          Object value = findValue(this.value);
          if (suppressEmptyParameters) {
          if (value != null && !value.toString().isEmpty())

          { component.addParameter(name, value); }

          } else

          { component.addParameter(name, value); }
          </code>

          existing code:
          <code>
          if (suppressEmptyParameters) {
          String potentialValue = (String) value;
          if (potentialValue != null && potentialValue.length() > 0) { component.addParameter(name, value); }
          } else { component.addParameter(name, value); }

          </code>

          Do you want me to create another issue?

          Cheers Greg

          Show
          Greg Huber added a comment - Lukasz, Sorry, but I have noticed that my patch does not handle integers correctly, alas, we need to do another change It does kind of the same check, but this works with integers/doubles. <code> Object value = findValue(this.value); if (suppressEmptyParameters) { if (value != null && !value.toString().isEmpty()) { component.addParameter(name, value); } } else { component.addParameter(name, value); } </code> existing code: <code> if (suppressEmptyParameters) { String potentialValue = (String) value; if (potentialValue != null && potentialValue.length() > 0) { component.addParameter(name, value); } } else { component.addParameter(name, value); } </code> Do you want me to create another issue? Cheers Greg
          Hide
          Greg Huber added a comment -

          patch to fix cast exceptions.

          Show
          Greg Huber added a comment - patch to fix cast exceptions.
          Hide
          Rene Gielen added a comment -

          Greg, thanks for the patch. I haven't yet reviewed it, but I have another question: mid November I reached out to you on behalf of the Struts PMC via the email address provided in your JIRA user profile. Since we did not hear back from you, I am afraid our mail did not reach you. Could you please contact me? rgielen at apache dot org.
          Thanks in advance

          Show
          Rene Gielen added a comment - Greg, thanks for the patch. I haven't yet reviewed it, but I have another question: mid November I reached out to you on behalf of the Struts PMC via the email address provided in your JIRA user profile. Since we did not hear back from you, I am afraid our mail did not reach you. Could you please contact me? rgielen at apache dot org. Thanks in advance
          Hide
          Greg Huber added a comment -

          See WW-4275

          Show
          Greg Huber added a comment - See WW-4275

            People

            • Assignee:
              Lukasz Lenart
              Reporter:
              Greg Huber
            • Votes:
              0 Vote for this issue
              Watchers:
              5 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved:

                Development