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
This commit is contained in:
Donald J. Brown
2008-06-17 10:14:25 +00:00
parent 5476f03918
commit 7dc0031e33
2 changed files with 27 additions and 0 deletions
@@ -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)) {
@@ -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);