diff --git a/plugins/portlet/src/main/java/org/apache/struts2/portlet/PortletActionConstants.java b/plugins/portlet/src/main/java/org/apache/struts2/portlet/PortletActionConstants.java index f913cb124..7078f0023 100644 --- a/plugins/portlet/src/main/java/org/apache/struts2/portlet/PortletActionConstants.java +++ b/plugins/portlet/src/main/java/org/apache/struts2/portlet/PortletActionConstants.java @@ -103,4 +103,14 @@ public interface PortletActionConstants { * {@link org.apache.struts2.portlet.context.PortletActionContext}. */ String DEFAULT_ACTION_FOR_MODE = "struts.portlet.defaultActionForMode"; + + /** + * Key for request attribute indicating if the action has been reset. + */ + String ACTION_RESET = "struts.portlet.actionReset"; + + /** + * Key for session attribute indicating the location of the render direct action. + */ + String RENDER_DIRECT_LOCATION = "struts.portlet.renderDirectLocation"; } diff --git a/plugins/portlet/src/main/java/org/apache/struts2/portlet/dispatcher/DirectRenderFromEventAction.java b/plugins/portlet/src/main/java/org/apache/struts2/portlet/dispatcher/DirectRenderFromEventAction.java index 4028b5604..4266e405d 100644 --- a/plugins/portlet/src/main/java/org/apache/struts2/portlet/dispatcher/DirectRenderFromEventAction.java +++ b/plugins/portlet/src/main/java/org/apache/struts2/portlet/dispatcher/DirectRenderFromEventAction.java @@ -23,6 +23,10 @@ package org.apache.struts2.portlet.dispatcher; import com.opensymphony.xwork2.Action; import java.io.Serializable; +import java.util.Map; + +import org.apache.struts2.interceptor.SessionAware; +import org.apache.struts2.portlet.PortletActionConstants; /** * When a portlet is targetted for an event, the portlet will receive two @@ -38,7 +42,7 @@ import java.io.Serializable; * specifying this action and the location of the view, which then will be executed in the * following render request. */ -public class DirectRenderFromEventAction implements Action, Serializable { +public class DirectRenderFromEventAction implements SessionAware, PortletActionConstants, Action, Serializable { private static final long serialVersionUID = -1814807772308405785L; @@ -53,15 +57,6 @@ public class DirectRenderFromEventAction implements Action, Serializable { return location; } - /** - * Set the location of the view. - * - * @param location The location to set. - */ - public void setLocation(String location) { - this.location = location; - } - /** * Always return success. * @@ -70,4 +65,8 @@ public class DirectRenderFromEventAction implements Action, Serializable { public String execute() throws Exception { return SUCCESS; } + + public void setSession(Map session) { + location = (String)session.get(RENDER_DIRECT_LOCATION); + } } diff --git a/plugins/portlet/src/main/java/org/apache/struts2/portlet/result/PortletResult.java b/plugins/portlet/src/main/java/org/apache/struts2/portlet/result/PortletResult.java index d985dbc49..6baf0d5b3 100644 --- a/plugins/portlet/src/main/java/org/apache/struts2/portlet/result/PortletResult.java +++ b/plugins/portlet/src/main/java/org/apache/struts2/portlet/result/PortletResult.java @@ -21,6 +21,7 @@ package org.apache.struts2.portlet.result; import java.io.IOException; +import java.util.Map; import java.util.StringTokenizer; import javax.portlet.ActionResponse; @@ -48,7 +49,7 @@ import com.opensymphony.xwork2.util.TextUtils; * Result type that includes a JSP to render. * */ -public class PortletResult extends StrutsResultSupport { +public class PortletResult extends StrutsResultSupport implements PortletActionConstants { private static final long serialVersionUID = 434251393926178567L; @@ -131,11 +132,12 @@ public class PortletResult extends StrutsResultSupport { // View is rendered with a view action...luckily... finalLocation = finalLocation.substring(0, finalLocation .lastIndexOf(".")); - res.setRenderParameter(PortletActionConstants.ACTION_PARAM, finalLocation); + res.setRenderParameter(ACTION_PARAM, finalLocation); } else { // View is rendered outside an action...uh oh... - res.setRenderParameter(PortletActionConstants.ACTION_PARAM, "renderDirect"); - res.setRenderParameter("location", finalLocation); + res.setRenderParameter(ACTION_PARAM, "renderDirect"); + Map sessionMap = invocation.getInvocationContext().getSession(); + sessionMap.put(RENDER_DIRECT_LOCATION, finalLocation); } res.setRenderParameter(PortletActionConstants.MODE_PARAM, PortletActionContext .getRequest().getPortletMode().toString()); diff --git a/plugins/portlet/src/test/java/org/apache/struts2/portlet/result/PortletResultTest.java b/plugins/portlet/src/test/java/org/apache/struts2/portlet/result/PortletResultTest.java index 5aa9feae4..da6949c68 100644 --- a/plugins/portlet/src/test/java/org/apache/struts2/portlet/result/PortletResultTest.java +++ b/plugins/portlet/src/test/java/org/apache/struts2/portlet/result/PortletResultTest.java @@ -34,6 +34,7 @@ import javax.portlet.RenderResponse; import junit.textui.TestRunner; +import org.apache.struts2.StrutsConstants; import org.apache.struts2.portlet.PortletActionConstants; import org.jmock.Mock; import org.jmock.cglib.MockObjectTestCase; @@ -46,7 +47,7 @@ import com.opensymphony.xwork2.ActionInvocation; * PortletResultTest. Insert description. * */ -public class PortletResultTest extends MockObjectTestCase { +public class PortletResultTest extends MockObjectTestCase implements PortletActionConstants { Mock mockInvocation = null; Mock mockConfig = null; @@ -148,17 +149,18 @@ public class PortletResultTest extends MockObjectTestCase { Constraint[] params = new Constraint[]{eq(PortletActionConstants.ACTION_PARAM), eq("renderDirect")}; mockResponse.expects(once()).method("setRenderParameter").with(params); - params = new Constraint[]{eq("location"), eq("/WEB-INF/pages/testJsp.jsp")}; - mockResponse.expects(once()).method("setRenderParameter").with(params); params = new Constraint[]{eq(PortletActionConstants.MODE_PARAM), eq(PortletMode.VIEW.toString())}; mockResponse.expects(once()).method("setRenderParameter").with(params); mockRequest.stubs().method("getPortletMode").will(returnValue(PortletMode.VIEW)); ActionContext ctx = ActionContext.getContext(); + Map session = new HashMap(); + ctx.put(PortletActionConstants.REQUEST, mockRequest.proxy()); ctx.put(PortletActionConstants.RESPONSE, mockResponse.proxy()); ctx.put(PortletActionConstants.PHASE, PortletActionConstants.EVENT_PHASE); + ctx.put(ActionContext.SESSION, session); PortletResult result = new PortletResult(); try { @@ -168,6 +170,7 @@ public class PortletResultTest extends MockObjectTestCase { e.printStackTrace(); fail("Error occured!"); } + assertEquals("/WEB-INF/pages/testJsp.jsp", session.get(RENDER_DIRECT_LOCATION)); } public void testDoExecute_event_locationHasQueryParams() {