Author: hermanns Date: Sat Jun 21 06:01:53 2008 New Revision: 670193 URL: http://svn.apache.org/viewvc?rev=670193&view=rev Log: WW-2678 portlet dispatching after action phase renders in wrong namespace o applied slightly modified patch submitted by Herbert Poul
Modified: struts/struts2/trunk/plugins/portlet/src/main/java/org/apache/struts2/portlet/result/PortletResult.java struts/struts2/trunk/plugins/portlet/src/main/java/org/apache/struts2/portlet/result/PortletVelocityResult.java struts/struts2/trunk/plugins/portlet/src/test/java/org/apache/struts2/portlet/result/PortletResultTest.java Modified: struts/struts2/trunk/plugins/portlet/src/main/java/org/apache/struts2/portlet/result/PortletResult.java URL: http://svn.apache.org/viewvc/struts/struts2/trunk/plugins/portlet/src/main/java/org/apache/struts2/portlet/result/PortletResult.java?rev=670193&r1=670192&r2=670193&view=diff ============================================================================== --- struts/struts2/trunk/plugins/portlet/src/main/java/org/apache/struts2/portlet/result/PortletResult.java (original) +++ struts/struts2/trunk/plugins/portlet/src/main/java/org/apache/struts2/portlet/result/PortletResult.java Sat Jun 21 06:01:53 2008 @@ -140,7 +140,12 @@ res.setRenderParameter(ACTION_PARAM, finalLocation); } else { // View is rendered outside an action...uh oh... - res.setRenderParameter(ACTION_PARAM, "renderDirect"); + String namespace = invocation.getProxy().getNamespace(); + if ( namespace != null && namespace.length() > 0 && !namespace.endsWith("/")) { + namespace += namespace + "/"; + + } + res.setRenderParameter(ACTION_PARAM, namespace + "renderDirect"); sessionMap.put(RENDER_DIRECT_LOCATION, finalLocation); } if(portletMode != null) { Modified: struts/struts2/trunk/plugins/portlet/src/main/java/org/apache/struts2/portlet/result/PortletVelocityResult.java URL: http://svn.apache.org/viewvc/struts/struts2/trunk/plugins/portlet/src/main/java/org/apache/struts2/portlet/result/PortletVelocityResult.java?rev=670193&r1=670192&r2=670193&view=diff ============================================================================== --- struts/struts2/trunk/plugins/portlet/src/main/java/org/apache/struts2/portlet/result/PortletVelocityResult.java (original) +++ struts/struts2/trunk/plugins/portlet/src/main/java/org/apache/struts2/portlet/result/PortletVelocityResult.java Sat Jun 21 06:01:53 2008 @@ -136,8 +136,12 @@ ActionInvocation invocation) { ActionResponse res = PortletActionContext.getActionResponse(); // View is rendered outside an action...uh oh... - res.setRenderParameter(PortletActionConstants.ACTION_PARAM, - "freemarkerDirect"); + String namespace = invocation.getProxy().getNamespace(); + if ( namespace != null && namespace.length() > 0 && !namespace.endsWith("/")) { + namespace += namespace + "/"; + + } + res.setRenderParameter(PortletActionConstants.ACTION_PARAM, namespace + "freemarkerDirect"); res.setRenderParameter("location", location); res.setRenderParameter(PortletActionConstants.MODE_PARAM, PortletActionContext .getRequest().getPortletMode().toString()); Modified: struts/struts2/trunk/plugins/portlet/src/test/java/org/apache/struts2/portlet/result/PortletResultTest.java URL: http://svn.apache.org/viewvc/struts/struts2/trunk/plugins/portlet/src/test/java/org/apache/struts2/portlet/result/PortletResultTest.java?rev=670193&r1=670192&r2=670193&view=diff ============================================================================== --- struts/struts2/trunk/plugins/portlet/src/test/java/org/apache/struts2/portlet/result/PortletResultTest.java (original) +++ struts/struts2/trunk/plugins/portlet/src/test/java/org/apache/struts2/portlet/result/PortletResultTest.java Sat Jun 21 06:01:53 2008 @@ -44,6 +44,9 @@ import com.opensymphony.xwork2.ActionContext; import com.opensymphony.xwork2.ActionInvocation; +import com.opensymphony.xwork2.ActionProxy; +import com.opensymphony.xwork2.mock.MockActionProxy; +import com.opensymphony.xwork2.mock.MockActionInvocation; /** * PortletResultTest. Insert description. @@ -139,12 +142,16 @@ public void testDoExecute_event_locationIsJsp() { Mock mockRequest = mock(ActionRequest.class); Mock mockResponse = mock(ActionResponse.class); + Mock mockProxy = mock(ActionProxy.class); Constraint[] params = new Constraint[]{eq(PortletActionConstants.ACTION_PARAM), eq("renderDirect")}; 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)); + mockProxy.stubs().method("getNamespace").will(returnValue("")); + + mockInvocation.stubs().method("getProxy").will(returnValue(mockProxy.proxy())); ActionContext ctx = ActionContext.getContext();