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

VotersWatch issueWatchersLinkCloneUpdate Comment AuthorReplace String in CommentUpdate Comment VisibilityDelete Comments
    XMLWordPrintableJSON

Details

    • Bug
    • Status: Closed
    • Major
    • Resolution: Fixed
    • 2.3.15.1
    • 2.3.16
    • None
    • 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.

      Attachments

        Activity

          This comment will be Viewable by All Users Viewable by All Users
          Cancel

          People

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

            Dates

              Created:
              Updated:
              Resolved:

              Slack

                Issue deployment