diff --git a/core/src/main/java/org/apache/struts2/components/ActionComponent.java b/core/src/main/java/org/apache/struts2/components/ActionComponent.java
index 45feff4cb..aeca699d8 100644
--- a/core/src/main/java/org/apache/struts2/components/ActionComponent.java
+++ b/core/src/main/java/org/apache/struts2/components/ActionComponent.java
@@ -22,7 +22,9 @@ package org.apache.struts2.components;
import java.io.IOException;
import java.io.Writer;
+import java.lang.reflect.Array;
import java.util.HashMap;
+import java.util.Iterator;
import java.util.Map;
import javax.servlet.ServletContext;
@@ -59,8 +61,8 @@ import com.opensymphony.xwork2.util.ValueStackFactory;
*
id (String) - the id (if specified) to put the action under stack's context.
* name* (String) - name of the action to be executed (without the extension suffix eg. .action)
* namespace (String) - default to the namespace where this action tag is invoked
- * executeResult (Boolean) - default is false. Decides wheather the result of this action is to be executed or not
- * ignoreContextParams (Boolean) - default to false. Decides wheather the request parameters are to be included when the action is invoked
+ * executeResult (Boolean) - default is false. Decides whether the result of this action is to be executed or not
+ * ignoreContextParams (Boolean) - default to false. Decides whether the request parameters are to be included when the action is invoked
*
*
*
@@ -170,18 +172,8 @@ public class ActionComponent extends ContextBean {
return end;
}
- private Map createExtraContext() {
- Map parentParams = null;
-
- if (!ignoreContextParams) {
- parentParams = new ActionContext(getStack().getContext()).getParameters();
- }
-
- Map newParams = (parentParams != null) ? new HashMap(parentParams) : new HashMap();
-
- if (parameters != null) {
- newParams.putAll(parameters);
- }
+ protected Map createExtraContext() {
+ Map newParams = createParametersForContext();
ActionContext ctx = new ActionContext(stack.getContext());
ServletContext servletContext = (ServletContext) ctx.get(ServletActionContext.SERVLET_CONTEXT);
@@ -207,6 +199,40 @@ public class ActionComponent extends ContextBean {
return extraContext;
}
+ /**
+ * Creates parameters map using parameters from the value stack and component parameters. Any non-String array
+ * values will be converted into a single-value String array.
+ *
+ * @return A map of String[] parameters
+ */
+ protected Map createParametersForContext() {
+ Map parentParams = null;
+
+ if (!ignoreContextParams) {
+ parentParams = new ActionContext(getStack().getContext()).getParameters();
+ }
+
+ Map newParams = (parentParams != null)
+ ? new HashMap(parentParams)
+ : new HashMap();
+
+ if (parameters != null) {
+ Map params = new HashMap();
+ for (Iterator i = parameters.entrySet().iterator(); i.hasNext(); ) {
+ Map.Entry entry = (Map.Entry) i.next();
+ String key = (String) entry.getKey();
+ Object val = entry.getValue();
+ if (val.getClass().isArray() && String.class == val.getClass().getComponentType()) {
+ params.put(key, (String[])val);
+ } else {
+ params.put(key, new String[]{val.toString()});
+ }
+ }
+ newParams.putAll(params);
+ }
+ return newParams;
+ }
+
public ActionProxy getProxy() {
return proxy;
}
diff --git a/core/src/test/java/org/apache/struts2/components/ActionComponentTest.java b/core/src/test/java/org/apache/struts2/components/ActionComponentTest.java
new file mode 100644
index 000000000..027724423
--- /dev/null
+++ b/core/src/test/java/org/apache/struts2/components/ActionComponentTest.java
@@ -0,0 +1,54 @@
+/*
+ * $Id: ComponentTest.java 471756 2006-11-06 15:01:43Z husted $
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.struts2.components;
+
+import java.util.HashMap;
+import java.util.Map;
+
+import org.apache.struts2.StrutsTestCase;
+import org.springframework.mock.web.MockHttpServletRequest;
+import org.springframework.mock.web.MockHttpServletResponse;
+
+import com.mockobjects.dynamic.Mock;
+import com.opensymphony.xwork2.util.ValueStack;
+
+public class ActionComponentTest extends StrutsTestCase {
+
+ public void testCreateParametersForContext() throws Exception {
+ MockHttpServletRequest req = new MockHttpServletRequest();
+ MockHttpServletResponse res = new MockHttpServletResponse();
+ Mock mockValueStack = new Mock(ValueStack.class);
+ HashMap ctx = new HashMap();
+ mockValueStack.expectAndReturn("getContext", ctx);
+ mockValueStack.expectAndReturn("getContext", ctx);
+ mockValueStack.expectAndReturn("getContext", ctx);
+
+ ActionComponent comp = new ActionComponent((ValueStack) mockValueStack.proxy(), req, res);
+ comp.addParameter("foo", "bar");
+ comp.addParameter("baz", new String[]{"jim", "sarah"});
+ Map params = comp.createParametersForContext();
+ assertNotNull(params);
+ assertEquals(2, params.size());
+ assertEquals("bar", ((String[])params.get("foo"))[0]);
+ assertEquals(2, ((String[])params.get("baz")).length);
+ mockValueStack.verify();
+ }
+}