WW-2052 Put location from renderDirect action in session instead of render parameter

git-svn-id: https://svn.apache.org/repos/asf/struts/struts2/trunk@564120 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Nils-Helge Garli
2007-08-09 07:14:51 +00:00
parent 463ce50112
commit bdbe0bf7f9
4 changed files with 31 additions and 17 deletions
@@ -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";
}
@@ -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 <code>event</code>, 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);
}
}
@@ -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());
@@ -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() {