Author: musachy
Date: Mon Nov 16 19:42:15 2009
New Revision: 880928
URL: http://svn.apache.org/viewvc?rev=880928&view=rev
Log:
WW-3330 <@s.action> broken in sitemesh freemarker decorator page. Add a request
attribute that marks a request as a request from an action tag., so other parts
of the framework can act accordingly. I think this is not good, but this whole
"action" tag is an antipattern, so some hacks are needed to get it to work.
Modified:
struts/struts2/trunk/core/src/main/java/org/apache/struts2/StrutsStatics.java
struts/struts2/trunk/core/src/main/java/org/apache/struts2/components/ActionComponent.java
struts/struts2/trunk/core/src/main/java/org/apache/struts2/dispatcher/ServletDispatcherResult.java
struts/struts2/trunk/core/src/test/java/org/apache/struts2/dispatcher/ServletDispatcherResultTest.java
Modified:
struts/struts2/trunk/core/src/main/java/org/apache/struts2/StrutsStatics.java
URL:
http://svn.apache.org/viewvc/struts/struts2/trunk/core/src/main/java/org/apache/struts2/StrutsStatics.java?rev=880928&r1=880927&r2=880928&view=diff
==============================================================================
---
struts/struts2/trunk/core/src/main/java/org/apache/struts2/StrutsStatics.java
(original)
+++
struts/struts2/trunk/core/src/main/java/org/apache/struts2/StrutsStatics.java
Mon Nov 16 19:42:15 2009
@@ -66,4 +66,10 @@
/** Constant for the PortletContext object */
public static final String STRUTS_PORTLET_CONTEXT =
"struts.portlet.context";
+
+ /**
+ * Set as an attribute in the request to let other parts of the framework
know that the invocation is happening inside an
+ * action tag
+ */
+ public static final String STRUTS_ACTION_TAG_INVOCATION=
"struts.actiontag.invocation";
}
Modified:
struts/struts2/trunk/core/src/main/java/org/apache/struts2/components/ActionComponent.java
URL:
http://svn.apache.org/viewvc/struts/struts2/trunk/core/src/main/java/org/apache/struts2/components/ActionComponent.java?rev=880928&r1=880927&r2=880928&view=diff
==============================================================================
---
struts/struts2/trunk/core/src/main/java/org/apache/struts2/components/ActionComponent.java
(original)
+++
struts/struts2/trunk/core/src/main/java/org/apache/struts2/components/ActionComponent.java
Mon Nov 16 19:42:15 2009
@@ -34,6 +34,7 @@
import org.apache.struts2.ServletActionContext;
import org.apache.struts2.StrutsException;
+import org.apache.struts2.StrutsStatics;
import org.apache.struts2.dispatcher.Dispatcher;
import org.apache.struts2.dispatcher.RequestMap;
import org.apache.struts2.dispatcher.mapper.ActionMapper;
@@ -286,6 +287,7 @@
proxy = actionProxyFactory.createActionProxy(namespace,
actionName, methodName, createExtraContext(), executeResult, true);
// set the new stack into the request for the taglib to use
req.setAttribute(ServletActionContext.STRUTS_VALUESTACK_KEY,
proxy.getInvocation().getStack());
+ req.setAttribute(StrutsStatics.STRUTS_ACTION_TAG_INVOCATION,
Boolean.TRUE);
proxy.execute();
} catch (Exception e) {
@@ -295,6 +297,7 @@
throw new StrutsException(message, e);
}
} finally {
+ req.removeAttribute(StrutsStatics.STRUTS_ACTION_TAG_INVOCATION);
// set the old stack back on the request
req.setAttribute(ServletActionContext.STRUTS_VALUESTACK_KEY,
stack);
if (inv != null) {
Modified:
struts/struts2/trunk/core/src/main/java/org/apache/struts2/dispatcher/ServletDispatcherResult.java
URL:
http://svn.apache.org/viewvc/struts/struts2/trunk/core/src/main/java/org/apache/struts2/dispatcher/ServletDispatcherResult.java?rev=880928&r1=880927&r2=880928&view=diff
==============================================================================
---
struts/struts2/trunk/core/src/main/java/org/apache/struts2/dispatcher/ServletDispatcherResult.java
(original)
+++
struts/struts2/trunk/core/src/main/java/org/apache/struts2/dispatcher/ServletDispatcherResult.java
Mon Nov 16 19:42:15 2009
@@ -29,7 +29,9 @@
import javax.servlet.jsp.PageContext;
import org.apache.struts2.ServletActionContext;
+import org.apache.struts2.StrutsStatics;
import org.apache.struts2.views.util.UrlHelper;
+import org.apache.commons.lang.xwork.ObjectUtils;
import com.opensymphony.xwork2.ActionInvocation;
import com.opensymphony.xwork2.util.logging.Logger;
@@ -144,10 +146,13 @@
return;
}
+ //if we are inside an action tag, we always need to do an include
+ Boolean insideActionTag = (Boolean)
ObjectUtils.defaultIfNull(request.getAttribute(StrutsStatics.STRUTS_ACTION_TAG_INVOCATION),
Boolean.FALSE);
+
// If we're included, then include the view
// Otherwise do forward
// This allow the page to, for example, set content type
- if (!response.isCommitted() &&
(request.getAttribute("javax.servlet.include.servlet_path") == null)) {
+ if (!insideActionTag && !response.isCommitted() &&
(request.getAttribute("javax.servlet.include.servlet_path") == null)) {
request.setAttribute("struts.view_uri", finalLocation);
request.setAttribute("struts.request_uri",
request.getRequestURI());
Modified:
struts/struts2/trunk/core/src/test/java/org/apache/struts2/dispatcher/ServletDispatcherResultTest.java
URL:
http://svn.apache.org/viewvc/struts/struts2/trunk/core/src/test/java/org/apache/struts2/dispatcher/ServletDispatcherResultTest.java?rev=880928&r1=880927&r2=880928&view=diff
==============================================================================
---
struts/struts2/trunk/core/src/test/java/org/apache/struts2/dispatcher/ServletDispatcherResultTest.java
(original)
+++
struts/struts2/trunk/core/src/test/java/org/apache/struts2/dispatcher/ServletDispatcherResultTest.java
Mon Nov 16 19:42:15 2009
@@ -49,6 +49,7 @@
dispatcherMock.expect("include", C.ANY_ARGS);
Mock requestMock = new Mock(HttpServletRequest.class);
+ requestMock.expectAndReturn("getAttribute",
"struts.actiontag.invocation", null);
requestMock.expectAndReturn("getRequestDispatcher",
C.args(C.eq("foo.jsp")), dispatcherMock.proxy());
Mock responseMock = new Mock(HttpServletResponse.class);
@@ -79,6 +80,7 @@
dispatcherMock.expect("forward", C.ANY_ARGS);
Mock requestMock = new Mock(HttpServletRequest.class);
+ requestMock.expectAndReturn("getAttribute",
"struts.actiontag.invocation", null);
requestMock.expectAndReturn("getAttribute",
"javax.servlet.include.servlet_path", null);
requestMock.expectAndReturn("getRequestDispatcher",
C.args(C.eq("foo.jsp")), dispatcherMock.proxy());
requestMock.expect("setAttribute", C.ANY_ARGS); // this is a bad mock,
but it works