Commits

Anonymous committed 205f980

XW-709 Add a "merge" attribute to the StaticParametersInterceptor to prevent it from merging static params with/ request params

git-svn-id: http://svn.opensymphony.com/svn/xwork/trunk@2021e221344d-f017-0410-9bd5-d282ab1896d7

Comments (0)

Files changed (2)

core/src/main/java/com/opensymphony/xwork2/interceptor/StaticParametersInterceptor.java

  *
  * This interceptor populates the action with the static parameters defined in the action configuration. If the action
  * implements {@link Parameterizable}, a map of the static parameters will be also be passed directly to the action.
+ * The static params will be added to the request params map, unless "merge" is set to false.
  *
  * <p/> Parameters are typically defined with &lt;param&gt; elements within xwork.xml.
  *
 
     private boolean parse;
     private boolean overwrite;
+    private boolean merge = true;
 
     static boolean devMode = false;
 
         this.parse = Boolean.valueOf(value).booleanValue();
     }
 
+     public void setMerge(String value) {
+        this.merge = Boolean.valueOf(value).booleanValue();
+    }
+
     /**
      * Overwrites already existing parameters from other sources.
      * Static parameters are the successor over previously set parameters, if true.
                         }
                     }
                 }
-                addParametersToContext(ac, parameters);
+
+                if (merge)
+                    addParametersToContext(ac, parameters);
             } finally {
                 ReflectionContextState.setCreatingNullObjects(contextMap, false);
                 ReflectionContextState.setReportingConversionErrors(contextMap, false);

core/src/test/java/com/opensymphony/xwork2/interceptor/StaticParametersInterceptorTest.java

 import com.opensymphony.xwork2.mock.MockActionProxy;
 
 import java.util.Map;
+import java.util.HashMap;
 
 /**
  * Unit test of {@link StaticParametersInterceptor}.
         assertEquals("${top.hero}", user.getName());
     }
 
+     public void testNoMerge() throws Exception {
+        MockActionInvocation mai = new MockActionInvocation();
+        MockActionProxy map = new MockActionProxy();
+        ActionConfig ac = new ActionConfig.Builder("", "", "")
+                .addParam("top.name", "${top.hero}")
+                .build();
+        map.setConfig(ac);
+        mai.setProxy(map);
+        mai.setAction(new SimpleFooAction());
+
+        User user = new User();
+        ActionContext.getContext().getValueStack().push(user);
+        ActionContext.getContext().setParameters(new HashMap<String, Object>()); 
+        int before = ActionContext.getContext().getValueStack().size();
+        interceptor.setMerge("false");
+        interceptor.intercept(mai);
+
+        assertEquals(before, ActionContext.getContext().getValueStack().size());
+        assertEquals("${top.hero}", user.getName());
+        assertEquals(0, ActionContext.getContext().getParameters().size()); 
+    }
+
     public void testFewParametersParse() throws Exception {
         MockActionInvocation mai = new MockActionInvocation();
         MockActionProxy map = new MockActionProxy();