From 7dc0031e335f2eed744fd07c95749b72cfbd47ca Mon Sep 17 00:00:00 2001 From: "Donald J. Brown" Date: Tue, 17 Jun 2008 10:14:25 +0000 Subject: [PATCH] Fixing action tag so it doesn't set wrong action invocation WW-2611 git-svn-id: https://svn.apache.org/repos/asf/struts/struts2/trunk@668602 13f79535-47bb-0310-9956-ffa450edef68 --- .../struts2/components/ActionComponent.java | 5 +++++ .../struts2/views/jsp/ActionTagTest.java | 22 +++++++++++++++++++ 2 files changed, 27 insertions(+) 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 a1ff9ad65..3edaa3104 100644 --- a/core/src/main/java/org/apache/struts2/components/ActionComponent.java +++ b/core/src/main/java/org/apache/struts2/components/ActionComponent.java @@ -45,6 +45,7 @@ import org.apache.struts2.views.jsp.TagUtils; import com.opensymphony.xwork2.ActionContext; import com.opensymphony.xwork2.ActionProxy; import com.opensymphony.xwork2.ActionProxyFactory; +import com.opensymphony.xwork2.ActionInvocation; import com.opensymphony.xwork2.inject.Inject; import com.opensymphony.xwork2.util.ValueStack; import com.opensymphony.xwork2.util.ValueStackFactory; @@ -279,6 +280,7 @@ public class ActionComponent extends ContextBean { // get the old value stack from the request ValueStack stack = getStack(); // execute at this point, after params have been set + ActionInvocation inv = ActionContext.getContext().getActionInvocation(); try { proxy = actionProxyFactory.createActionProxy(namespace, actionName, methodName, createExtraContext(), executeResult, true); @@ -292,6 +294,9 @@ public class ActionComponent extends ContextBean { } finally { // set the old stack back on the request req.setAttribute(ServletActionContext.STRUTS_VALUESTACK_KEY, stack); + if (inv != null) { + ActionContext.getContext().setActionInvocation(inv); + } } if ((getVar() != null) && (proxy != null)) { diff --git a/core/src/test/java/org/apache/struts2/views/jsp/ActionTagTest.java b/core/src/test/java/org/apache/struts2/views/jsp/ActionTagTest.java index 6edd3b5f6..817a791b4 100644 --- a/core/src/test/java/org/apache/struts2/views/jsp/ActionTagTest.java +++ b/core/src/test/java/org/apache/struts2/views/jsp/ActionTagTest.java @@ -39,6 +39,7 @@ import com.opensymphony.xwork2.ActionInvocation; import com.opensymphony.xwork2.ActionProxy; import com.opensymphony.xwork2.util.ValueStack; import com.opensymphony.xwork2.util.ValueStackFactory; +import com.mockobjects.dynamic.Mock; /** @@ -147,6 +148,27 @@ public class ActionTagTest extends AbstractTagTest { assertNull(result); // result is never executed, hence never set into invocation } + public void testExecuteButResetReturnSameInvocation() throws Exception { + Mock mockActionInv = new Mock(ActionInvocation.class); + ActionTag tag = new ActionTag(); + tag.setPageContext(pageContext); + tag.setNamespace(""); + tag.setName("testActionTagAction"); + tag.setExecuteResult(true); + ActionContext.getContext().setActionInvocation((ActionInvocation) mockActionInv.proxy()); + + ActionInvocation oldInvocation = ActionContext.getContext().getActionInvocation(); + assertNotNull(oldInvocation); + + tag.doStartTag(); + + // tag clear components on doEndTag + ActionComponent component = (ActionComponent) tag.getComponent(); + + tag.doEndTag(); + assertTrue(oldInvocation == ActionContext.getContext().getActionInvocation()); + } + public void testIngoreContextParamsFalse() throws Exception { ActionTag tag = new ActionTag(); tag.setPageContext(pageContext);