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

Struts2 StaticParametersInterceptor's addParametersToContext method is not working as expected.

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Closed
    • Minor
    • Resolution: Fixed
    • None
    • 2.5.26, 6.0.0
    • None
    • None

    Description

      In our current project we are upgrading struts 2.3.35 to 2.5.22 and we encounter some minor bug in below code of addParametersToContext method of StaticParametersInterceptor.

      in method, code is like below.

       

      if (overwrite) {
                  if (previousParams != null) {
                      combinedParams = combinedParams.withParent(previousParams);
                  }
                  if (newParams != null) {
                      combinedParams = combinedParams.withExtraParams(newParams);
                  }
              } else {
                  if (newParams != null) {
                      combinedParams = combinedParams.withExtraParams(newParams);
                  }
                  if (previousParams != null) {
                      combinedParams = combinedParams.withParent(previousParams);
                  }
              }
      

       

      But here overwrite functionality will not work since only if condition order was changed in else condition of overwrite.

      instead of this, as per me, code would be like below

      if (overwrite) {
                  if (previousParams != null) {
                      combinedParams = combinedParams.withParent(previousParams);
                  }
                  if (newParams != null) {
                      combinedParams = combinedParams.withExtraParams(newParams);
                  }
              } else {
                  if (newParams != null) {  
                   HttpParameters newHttpParameters = HttpParameters.create(newParams).build();
                      combinedParams = combinedParams.withParent(newParams);
                  }
                  if (previousParams != null) {
                      combinedParams = combinedParams.withExtraParams(previousParams);
                  }
              }
      

       

      And that's how ac.setParameters(combinedParams.build()); will work because in build method, requestParameterMap will override parent parameters.

       

      Attachments

        Activity

          People

            Unassigned Unassigned
            akash.shah Akash Shah
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:

              Time Tracking

                Estimated:
                Original Estimate - Not Specified
                Not Specified
                Remaining:
                Remaining Estimate - 0h
                0h
                Logged:
                Time Spent - 3h 20m
                3h 20m