Commits

jcarreira  committed 94f6126

WW-677: include tag now makes sure the ActionContext is not overridden if it includes an action

also fixed an issue where using the ActionTag could override values in the ActionContext / ValueStack context when the new ActionProxy is created by the ActionTag.

git-svn-id: http://svn.opensymphony.com/svn/webwork/trunk@619573baa09-0c28-0410-bef9-dab3c582ae83

  • Participants
  • Parent commits 4b5f264

Comments (0)

Files changed (12)

File lib/core/xwork.jar

Binary file modified.

File src/etc/example/xwork.xml

 
         <action name="exception" class="com.opensymphony.webwork.example.ExceptionAction">
         </action>
+        
+        <action name="includeTest" class="com.opensymphony.xwork.ActionSupport">
+            <result name="success">includetagtest.jsp</result>
+        </action>
+
+        <action name="included" class="com.opensymphony.webwork.example.Test">
+            <result name="success">included.jsp</result>
+        </action>
 
         <action name="basicValidation" class="com.opensymphony.webwork.example.ValidatedAction">
             <interceptor-ref name="validationWorkflowStack"/>

File src/java/com/opensymphony/webwork/ServletActionContext.java

  * @author Bill Lynch (docs)
  */
 public class ServletActionContext extends ActionContext implements WebWorkStatics {
+    public static final String WEBWORK_VALUESTACK_KEY = "webwork.valueStack";
     //~ Constructors ///////////////////////////////////////////////////////////
 
     private ServletActionContext(Map context) {

File src/java/com/opensymphony/webwork/dispatcher/FilterDispatcher.java

 package com.opensymphony.webwork.dispatcher;
 
 import com.opensymphony.webwork.WebWorkStatics;
+import com.opensymphony.webwork.ServletActionContext;
 import com.opensymphony.xwork.ActionContext;
 import com.opensymphony.xwork.ActionProxy;
 import com.opensymphony.xwork.ActionProxyFactory;
         // check to see if maybe the ServletDispatcher already fielded this?
         boolean invoked = false;
 
-        if (request.getAttribute("webwork.valueStack") == null) {
+        if (request.getAttribute(ServletActionContext.WEBWORK_VALUESTACK_KEY) == null) {
             Map namespaceAction = (Map) config.get(request.getServletPath());
 
             if (namespaceAction != null) {
 
                 try {
                     ActionProxy proxy = ActionProxyFactory.getFactory().createActionProxy(namespace, actionName, extraContext);
-                    request.setAttribute("webwork.valueStack", proxy.getInvocation().getStack());
+                    request.setAttribute(ServletActionContext.WEBWORK_VALUESTACK_KEY, proxy.getInvocation().getStack());
                     proxy.execute();
                 } catch (Exception e) {
                     try {

File src/java/com/opensymphony/webwork/dispatcher/ServletDispatcher.java

 
 import com.opensymphony.util.FileManager;
 import com.opensymphony.webwork.WebWorkStatics;
+import com.opensymphony.webwork.ServletActionContext;
 import com.opensymphony.webwork.config.Configuration;
 import com.opensymphony.webwork.dispatcher.multipart.MultiPartRequest;
 import com.opensymphony.webwork.dispatcher.multipart.MultiPartRequestWrapper;
  * <li>{@link #getSessionMap(HttpServletRequest)}</li>
  * <li>{@link #getNameSpace(HttpServletRequest)}</li></ul>
  *
- * @author <a href="mailto:rickard@middleware-company.com">Rickard �berg</a>
+ * @author <a href="mailto:rickard@middleware-company.com">Rickard �berg</a>
  * @author <a href="mailto:matt@smallleap.com">Matt Baldree</a>
  * @author Jason Carreira
  * @author <a href="mailto:cameron@datacodex.net">Cameron Braid</a>
 
         try {
             ActionProxy proxy = ActionProxyFactory.getFactory().createActionProxy(namespace, actionName, extraContext);
-            request.setAttribute("webwork.valueStack", proxy.getInvocation().getStack());
+            request.setAttribute(ServletActionContext.WEBWORK_VALUESTACK_KEY, proxy.getInvocation().getStack());
             proxy.execute();
         } catch (ConfigurationException e) {
             log.error("Could not find action", e);

File src/java/com/opensymphony/webwork/interceptor/TokenSessionStoreInterceptor.java

             if (savedInvocation != null) {
                 // set the valuestack to the request scope
                 OgnlValueStack stack = savedInvocation.getStack();
-                ServletActionContext.getRequest().setAttribute("webwork.valueStack", stack);
+                ServletActionContext.getRequest().setAttribute(ServletActionContext.WEBWORK_VALUESTACK_KEY, stack);
 
                 Result result = savedInvocation.getResult();
 

File src/java/com/opensymphony/webwork/views/jsp/ActionTag.java

         extraContext.put(PAGE_CONTEXT, pageContext);
 
         OgnlValueStack vs = ActionContext.getContext().getValueStack();
-        extraContext.put(ActionContext.VALUE_STACK, vs);
+        OgnlValueStack newStack = new OgnlValueStack(vs);
+        extraContext.put(ActionContext.VALUE_STACK, newStack);
 
         return extraContext;
     }

File src/java/com/opensymphony/webwork/views/jsp/IncludeTag.java

 
 import com.opensymphony.webwork.config.Configuration;
 import com.opensymphony.webwork.util.FastByteArrayOutputStream;
+import com.opensymphony.webwork.ServletActionContext;
+import com.opensymphony.xwork.util.OgnlValueStack;
 import org.apache.commons.logging.LogFactory;
 
 import javax.servlet.RequestDispatcher;
 /**
  * Include a servlet's output (result of servlet or a JSP page).
  *
- * @author Rickard �berg (rickard@dreambean.com)
+ * @author Rickard �berg (rickard@dreambean.com)
  * @author <a href="mailto:scott@atlassian.com">Scott Farquhar</a>
  * @version $Revision$
  */
     public int doEndTag() throws JspException {
         String page;
 
+        // Save the current value stack to set back into the request in case the include resets it
+        OgnlValueStack stack = getStack();
         // If value is set, we resolve it to get the page name
         if (valueAttr != null) {
             page = findString(valueAttr);
             LogFactory.getLog(getClass()).warn("Exception thrown during include of " + result, e);
             throw new JspTagException(e.toString());
         }
+        // Set the old value stack back into the request just in case it's been set by the include
+        pageContext.getRequest().setAttribute(ServletActionContext.WEBWORK_VALUESTACK_KEY,stack);
 
         return EVAL_PAGE;
     }

File src/java/com/opensymphony/webwork/views/jsp/TagUtils.java

 
     public static OgnlValueStack getStack(PageContext pageContext) {
         HttpServletRequest req = (HttpServletRequest) pageContext.getRequest();
-        OgnlValueStack stack = (OgnlValueStack) req.getAttribute("webwork.valueStack");
+        OgnlValueStack stack = (OgnlValueStack) req.getAttribute(ServletActionContext.WEBWORK_VALUESTACK_KEY);
 
         if (stack == null) {
             stack = new OgnlValueStack();
             Map extraContext = ServletDispatcher.createContextMap(new RequestMap(req), req.getParameterMap(), new SessionMap(req), new ApplicationMap(pageContext.getServletContext()), req, res, pageContext.getServletConfig());
             extraContext.put(ServletActionContext.PAGE_CONTEXT, pageContext);
             stack.getContext().putAll(extraContext);
-            req.setAttribute("webwork.valueStack", stack);
+            req.setAttribute(ServletActionContext.WEBWORK_VALUESTACK_KEY, stack);
 
             // also tie this stack/context to the ThreadLocal
             ActionContext.setContext(new ActionContext(stack.getContext()));

File src/test/com/opensymphony/webwork/views/jsp/AbstractTagTest.java

 package com.opensymphony.webwork.views.jsp;
 
 import com.opensymphony.webwork.TestAction;
+import com.opensymphony.webwork.ServletActionContext;
 import com.opensymphony.webwork.config.Configuration;
 import com.opensymphony.webwork.views.velocity.AbstractTagDirective;
 import com.opensymphony.xwork.Action;
         stack.push(action);
 
         request = new WebWorkMockHttpServletRequest();
-        request.setAttribute("webwork.valueStack", stack);
+        request.setAttribute(ServletActionContext.WEBWORK_VALUESTACK_KEY, stack);
         response = new WebWorkMockHttpServletResponse();
         request.setSession(new WebWorkMockHttpSession());
 

File src/webapp/included.jsp

+<%@ taglib prefix="ww" uri="webwork" %>
+<b>Current top of stack: <ww:property value="top"/></b>

File src/webapp/includetagtest.jsp

+<%@ taglib prefix="ww" uri="webwork" %>
+<html>
+<head><title>Include Tag Test</title></head>
+<body>
+
+<jsp:include page="included.jsp" />
+<br>
+<ww:include page="included.action"/>
+<br>
+<jsp:include page="included.jsp" />
+</body>
+</html>