Author: nilsga
Date: Mon Dec 1 10:34:38 2008
New Revision: 722163
URL: http://svn.apache.org/viewvc?rev=722163&view=rev
Log:
Fix for proper resource rendering (AJAX). Patch by Philipp Anokhin. Thanks!
Modified:
struts/sandbox/trunk/struts2-portlet2-plugin/src/main/java/org/apache/struts2/portlet/context/PortletActionContext.java
struts/sandbox/trunk/struts2-portlet2-plugin/src/main/java/org/apache/struts2/portlet/result/PortletResult.java
struts/sandbox/trunk/struts2-portlet2-plugin/src/main/java/org/apache/struts2/portlet/util/PortletUrlHelper.java
Modified:
struts/sandbox/trunk/struts2-portlet2-plugin/src/main/java/org/apache/struts2/portlet/context/PortletActionContext.java
URL:
http://svn.apache.org/viewvc/struts/sandbox/trunk/struts2-portlet2-plugin/src/main/java/org/apache/struts2/portlet/context/PortletActionContext.java?rev=722163&r1=722162&r2=722163&view=diff
==============================================================================
---
struts/sandbox/trunk/struts2-portlet2-plugin/src/main/java/org/apache/struts2/portlet/context/PortletActionContext.java
(original)
+++
struts/sandbox/trunk/struts2-portlet2-plugin/src/main/java/org/apache/struts2/portlet/context/PortletActionContext.java
Mon Dec 1 10:34:38 2008
@@ -164,6 +164,13 @@
}
/**
+ * @return <code>true</code> if the Portlet is executing in the resource
phase.
+ */
+ public static boolean isResource() {
+ return SERVE_RESOURCE_PHASE.equals(getPhase());
+ }
+
+ /**
* @return The current ActionContext.
*/
private static ActionContext getContext() {
Modified:
struts/sandbox/trunk/struts2-portlet2-plugin/src/main/java/org/apache/struts2/portlet/result/PortletResult.java
URL:
http://svn.apache.org/viewvc/struts/sandbox/trunk/struts2-portlet2-plugin/src/main/java/org/apache/struts2/portlet/result/PortletResult.java?rev=722163&r1=722162&r2=722163&view=diff
==============================================================================
---
struts/sandbox/trunk/struts2-portlet2-plugin/src/main/java/org/apache/struts2/portlet/result/PortletResult.java
(original)
+++
struts/sandbox/trunk/struts2-portlet2-plugin/src/main/java/org/apache/struts2/portlet/result/PortletResult.java
Mon Dec 1 10:34:38 2008
@@ -28,7 +28,8 @@
import javax.portlet.PortletException;
import javax.portlet.PortletMode;
import javax.portlet.PortletRequestDispatcher;
-import javax.portlet.RenderRequest;
+import javax.portlet.PortletRequest;
+import javax.portlet.MimeResponse;
import javax.portlet.RenderResponse;
import javax.portlet.StateAwareResponse;
import javax.servlet.ServletContext;
@@ -87,8 +88,8 @@
*/
public void doExecute(String finalLocation, ActionInvocation
actionInvocation) throws Exception {
- if (PortletActionContext.isRender()) {
- executeRenderResult(finalLocation);
+ if (PortletActionContext.isRender() ||
PortletActionContext.isResource()) {
+ executeMimeResult(finalLocation);
} else if (PortletActionContext.isAction() ||
PortletActionContext.isEvent()) {
executeActionResult(finalLocation, actionInvocation);
} else {
@@ -125,7 +126,8 @@
* @param invocation
*/
protected void executeActionResult(String finalLocation,
ActionInvocation invocation) throws Exception {
- LOG.debug("Executing result in Event phase");
+ String phase = (PortletActionContext.isEvent()) ? "Event" : "Action";
+ LOG.debug("Executing result in "+phase+" phase");
StateAwareResponse res =
(StateAwareResponse)PortletActionContext.getResponse();
Map sessionMap = invocation.getInvocationContext().getSession();
LOG.debug("Setting event render parameter: " + finalLocation);
@@ -168,38 +170,38 @@
}
}
- /**
- * Executes the render result.
- *
- * @param finalLocation
- * @throws PortletException
- * @throws IOException
- */
- protected void executeRenderResult(final String finalLocation) throws
PortletException, IOException {
- LOG.debug("Executing result in Render phase");
- PortletContext ctx = PortletActionContext.getPortletContext();
- RenderRequest req = PortletActionContext.getRenderRequest();
- RenderResponse res = PortletActionContext.getRenderResponse();
- res.setContentType(contentType);
- if (TextUtils.stringSet(title)) {
- res.setTitle(title);
- }
- LOG.debug("Location: " + finalLocation);
- if (useDispatcherServlet) {
- req.setAttribute(DISPATCH_TO, finalLocation);
- PortletRequestDispatcher dispatcher =
ctx.getNamedDispatcher(dispatcherServletName);
- if(dispatcher == null) {
- throw new PortletException("Could not locate
dispatcher servlet \"" + dispatcherServletName + "\". Please configure it in
your web.xml file");
- }
- dispatcher.include(req, res);
- } else {
- PortletRequestDispatcher dispatcher =
ctx.getRequestDispatcher(finalLocation);
- if (dispatcher == null) {
- throw new PortletException("Could not locate
dispatcher for '" + finalLocation + "'");
- }
- dispatcher.include(req, res);
- }
- }
+ /**
+ * Executes the render result.
+ *
+ * @param finalLocation
+ * @throws PortletException
+ * @throws IOException
+ */
+ protected void executeMimeResult(final String finalLocation) throws
PortletException, IOException {
+ LOG.debug("Executing mime result");
+ PortletContext ctx = PortletActionContext.getPortletContext();
+ PortletRequest req = PortletActionContext.getRequest();
+ MimeResponse res = (MimeResponse)PortletActionContext.getResponse();
+ res.setContentType(contentType);
+ if (TextUtils.stringSet(title) && res instanceof
RenderResponse) {
+ ((RenderResponse)res).setTitle(title);
+ }
+ LOG.debug("Location: " + finalLocation);
+ if (useDispatcherServlet) {
+ req.setAttribute(DISPATCH_TO, finalLocation);
+ PortletRequestDispatcher dispatcher =
ctx.getNamedDispatcher(dispatcherServletName);
+ if(dispatcher == null) {
+ throw new PortletException("Could not locate dispatcher
servlet \"" + dispatcherServletName + "\". Please configure it in your web.xml
file");
+ }
+ dispatcher.include(req, res);
+ } else {
+ PortletRequestDispatcher dispatcher =
ctx.getRequestDispatcher(finalLocation);
+ if (dispatcher == null) {
+ throw new PortletException("Could not locate dispatcher for '"
+ finalLocation + "'");
+ }
+ dispatcher.include(req, res);
+ }
+ }
/**
* Sets the content type.
Modified:
struts/sandbox/trunk/struts2-portlet2-plugin/src/main/java/org/apache/struts2/portlet/util/PortletUrlHelper.java
URL:
http://svn.apache.org/viewvc/struts/sandbox/trunk/struts2-portlet2-plugin/src/main/java/org/apache/struts2/portlet/util/PortletUrlHelper.java?rev=722163&r1=722162&r2=722163&view=diff
==============================================================================
---
struts/sandbox/trunk/struts2-portlet2-plugin/src/main/java/org/apache/struts2/portlet/util/PortletUrlHelper.java
(original)
+++
struts/sandbox/trunk/struts2-portlet2-plugin/src/main/java/org/apache/struts2/portlet/util/PortletUrlHelper.java
Mon Dec 1 10:34:38 2008
@@ -33,8 +33,8 @@
import javax.portlet.PortletMode;
import javax.portlet.PortletSecurityException;
import javax.portlet.PortletURL;
-import javax.portlet.RenderRequest;
-import javax.portlet.RenderResponse;
+import javax.portlet.PortletRequest;
+import javax.portlet.MimeResponse;
import javax.portlet.WindowState;
import org.apache.struts2.StrutsException;
@@ -47,8 +47,8 @@
* Helper class for creating Portlet URLs. Portlet URLs are fundamentally
different from regular
* servlet URLs since they never target the application itself; all requests
go through the portlet
* container and must therefore be programatically constructed using the
- * [EMAIL PROTECTED] javax.portlet.RenderResponse#createActionURL()} and
- * [EMAIL PROTECTED] javax.portlet.RenderResponse#createRenderURL()} APIs.
+ * [EMAIL PROTECTED] javax.portlet.MimeResponse#createActionURL()} and
+ * [EMAIL PROTECTED] javax.portlet.MimeResponse#createRenderURL()} APIs.
*
*/
public class PortletUrlHelper {
@@ -83,13 +83,13 @@
String scheme, String type, String portletMode, String windowState,
boolean includeContext, boolean encodeResult) {
StringBuffer resultingAction = new StringBuffer();
- RenderRequest request = PortletActionContext.getRenderRequest();
- RenderResponse response = PortletActionContext.getRenderResponse();
+ PortletRequest request = PortletActionContext.getRequest();
+ MimeResponse response =
(MimeResponse)PortletActionContext.getResponse();
LOG.debug("Creating url. Action = " + action + ", Namespace = "
+ namespace + ", Type = " + type);
namespace = prependNamespace(namespace, portletMode);
if (!TextUtils.stringSet(portletMode)) {
- portletMode =
PortletActionContext.getRenderRequest().getPortletMode().toString();
+ portletMode =
PortletActionContext.getRequest().getPortletMode().toString();
}
String result = null;
int paramStartIndex = action.indexOf('?');
@@ -170,7 +170,7 @@
*/
private static String prependNamespace(String namespace, String
portletMode) {
StringBuffer sb = new StringBuffer();
- PortletMode mode =
PortletActionContext.getRenderRequest().getPortletMode();
+ PortletMode mode = PortletActionContext.getRequest().getPortletMode();
if(TextUtils.stringSet(portletMode)) {
mode = new PortletMode(portletMode);
}
@@ -228,8 +228,8 @@
throw new StrutsException("Encoding "+ENCODING+" not found");
}
}
- RenderResponse resp = PortletActionContext.getRenderResponse();
- RenderRequest req = PortletActionContext.getRenderRequest();
+ MimeResponse resp = (MimeResponse)PortletActionContext.getResponse();
+ PortletRequest req = PortletActionContext.getRequest();
return resp.encodeURL(req.getContextPath() + sb.toString());
}
@@ -261,12 +261,12 @@
/**
* Convert the given String to a WindowState object.
*
- * @param portletReq The RenderRequest.
+ * @param portletReq The PortletRequest.
* @param windowState The WindowState as a String.
* @return The WindowState that mathces the <tt>windowState</tt> String,
or if
* the Sring is blank, the current WindowState.
*/
- private static WindowState getWindowState(RenderRequest portletReq,
+ private static WindowState getWindowState(PortletRequest portletReq,
String windowState) {
WindowState state = portletReq.getWindowState();
if (TextUtils.stringSet(windowState)) {
@@ -288,12 +288,12 @@
/**
* Convert the given String to a PortletMode object.
*
- * @param portletReq The RenderRequest.
+ * @param portletReq The PortletRequest.
* @param portletMode The PortletMode as a String.
* @return The PortletMode that mathces the <tt>portletMode</tt> String,
or if
* the Sring is blank, the current PortletMode.
*/
- private static PortletMode getPortletMode(RenderRequest portletReq,
+ private static PortletMode getPortletMode(PortletRequest portletReq,
String portletMode) {
PortletMode mode = portletReq.getPortletMode();