Uploaded image for project: 'Struts 2'
  1. Struts 2
  2. WW-4194

Using findValue() for value stack to retrieve component parameters always returns not-null object for any parameter name

    Details

    • Type: Bug
    • Status: Closed
    • Priority: Major
    • Resolution: Fixed
    • Affects Version/s: 2.3.15.1
    • Fix Version/s: 2.3.16
    • Component/s: None
    • Labels:
      None

      Description

      Calling valueStack.findValue("parameter.ANY_STRING") in a component returns not-null value even if there were no parameters passed to the component.

      Example:

      TestAction.java
      import com.opensymphony.xwork2.ActionSupport;
      import org.apache.struts2.interceptor.ServletRequestAware;
      
      import javax.servlet.http.HttpServletRequest;
      
      /**
       * @author Sergey Tychina
       */
      public class TestAction extends ActionSupport implements ServletRequestAware {
      
          private HttpServletRequest request;
      
          public String execute() {
              return SUCCESS;
          }
      
          @Override
          public void setServletRequest(HttpServletRequest request) {
              this.request = request;
          }
      }
      
      testaction.jsp (mapped for success result for the TestAction)
      <%@ taglib prefix="s" uri="/struts-tags" %>
      <s:component template="/testcomponent.jsp">
          <s:param name="testval" value="1"/>
      </s:component>
      
      testcomponent.jsp
      <%@ page import="com.opensymphony.xwork2.util.ValueStack" %>
      <%@ page import="org.apache.struts2.ServletActionContext" %>
      <%
          ValueStack valueStack = (ValueStack) request.getAttribute(ServletActionContext.STRUTS_VALUESTACK_KEY);
          Object foundValue = valueStack.findValue("parameters.ANY_PARAM_NAME");
      %>
      <%=foundValue == null ? "NULL" : "NOT NULL"%>
      

      This component will always print "NOT NULL" to the screen.

      Thanks,
      Sergey.

        Activity

        Hide
        bphillips Bruce Phillips added a comment -

        Luskaz tested in latest Struts 2 snapshot and reports the bug does not occur.

        Show
        bphillips Bruce Phillips added a comment - Luskaz tested in latest Struts 2 snapshot and reports the bug does not occur.
        Hide
        lukaszlenart Lukasz Lenart added a comment -

        NOT NULL NOT NULL when using 2.3.15 so problem magically solved

        Show
        lukaszlenart Lukasz Lenart added a comment - NOT NULL NOT NULL when using 2.3.15 so problem magically solved
        Hide
        lukaszlenart Lukasz Lenart added a comment -

        I'm using the latest SNAPSHOT

        Show
        lukaszlenart Lukasz Lenart added a comment - I'm using the latest SNAPSHOT
        Hide
        lukaszlenart Lukasz Lenart added a comment -

        NULL NOT NULL on Tomcat 7.0.40

        Show
        lukaszlenart Lukasz Lenart added a comment - NULL NOT NULL on Tomcat 7.0.40
        Hide
        lukaszlenart Lukasz Lenart added a comment -

        I have got that: NULL NOT NULL - on Jetty

        Show
        lukaszlenart Lukasz Lenart added a comment - I have got that: NULL NOT NULL - on Jetty
        Hide
        bphillips Bruce Phillips added a comment -
        Show
        bphillips Bruce Phillips added a comment - Is this related to: https://issues.apache.org/jira/browse/WW-3990
        Hide
        bphillips Bruce Phillips added a comment -

        To use the attached zipped project to demonstrate the problem follow these steps:

        After unzipping the download create the .war file by using mvn -e clean package

        Then copy the .war file to Tomcat's webapps directory

        Then go to: http://localhost:8080/Component_Tag_Struts2_Mvn/

        Click on the link to Register

        Complete the registration form and click submit

        You will see two NOT NULL statements

        The first NOT NULL statement should be NULL as the findValue statement in the testcomponent.jsp (line 5) is being used to find an object that does not exist in the ValueStack.

        Show
        bphillips Bruce Phillips added a comment - To use the attached zipped project to demonstrate the problem follow these steps: After unzipping the download create the .war file by using mvn -e clean package Then copy the .war file to Tomcat's webapps directory Then go to: http://localhost:8080/Component_Tag_Struts2_Mvn/ Click on the link to Register Complete the registration form and click submit You will see two NOT NULL statements The first NOT NULL statement should be NULL as the findValue statement in the testcomponent.jsp (line 5) is being used to find an object that does not exist in the ValueStack.
        Hide
        bphillips Bruce Phillips added a comment -

        I was able to duplicate the problem using the attached project. It appears using the Struts 2 component tag and a Struts 2 version after 2.3.14.3 will cause the problem.

        NOTE that the ValueStack method findValue when used within an Action class continues to work correctly (the value of foundValue is null).

        I'll research what we changed for the component tag between 2.3.14.3 and 2.3.15.

        Show
        bphillips Bruce Phillips added a comment - I was able to duplicate the problem using the attached project. It appears using the Struts 2 component tag and a Struts 2 version after 2.3.14.3 will cause the problem. NOTE that the ValueStack method findValue when used within an Action class continues to work correctly (the value of foundValue is null). I'll research what we changed for the component tag between 2.3.14.3 and 2.3.15.

          People

          • Assignee:
            bphillips Bruce Phillips
            Reporter:
            sergey.tychina@gmail.com Sergey Tychina
          • Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved:

              Development