Author: julien(a)jboss.com
Date: 2008-02-07 14:11:18 -0500 (Thu, 07 Feb 2008)
New Revision: 9839
Modified:
modules/portlet/trunk/test/src/main/java/org/jboss/portal/portlet/test/URLParameterConstants.java
modules/portlet/trunk/test/src/main/java/org/jboss/portal/portlet/test/controller/AbstractPortletControllerContext.java
modules/portlet/trunk/test/src/main/java/org/jboss/portal/portlet/test/controller/PortletURLRenderer.java
modules/portlet/trunk/test/src/main/java/org/jboss/portal/portlet/test/controller/TestPortletInvocationContext.java
modules/portlet/trunk/test/src/main/java/org/jboss/portal/portlet/test/jsp/ControllerFilter.java
Log:
- allow other type of invocations in PortletURLRenderer (for page refresh)
- make the jsp portal use redirect after action
Modified:
modules/portlet/trunk/test/src/main/java/org/jboss/portal/portlet/test/URLParameterConstants.java
===================================================================
---
modules/portlet/trunk/test/src/main/java/org/jboss/portal/portlet/test/URLParameterConstants.java 2008-02-07
18:31:21 UTC (rev 9838)
+++
modules/portlet/trunk/test/src/main/java/org/jboss/portal/portlet/test/URLParameterConstants.java 2008-02-07
19:11:18 UTC (rev 9839)
@@ -34,10 +34,21 @@
}
/**
+ * The type of request. The goal is to allow other types of invocation to be used by
the controller context.
+ * The controller context itself only works on the portlet type.
+ */
+ public static final String TYPE = "type";
+
+ /**
+ * The portlet type.
+ */
+ public static final String PORTLET_TYPE = "portlet";
+
+ /**
* The life cycle type of the invocation. The values accepted are
<code>ACTION_LIFECYCLE</code>,
* <code>RENDER_LIFECYCLE</code> and
<code>RESOURCE_LIFECYCLE</code>.
*/
- public static final String LIFECYCLE_TYPE = "type";
+ public static final String LIFECYCLE_PHASE = "lifecycle";
/** The window id. */
public static final String WINDOW_ID = "windowid";
@@ -70,12 +81,12 @@
public static final String RESOURCE_CACHEABILITY = "resourcecacheability";
/** Denotes an action lifecycle operation. */
- public static final String ACTION_LIFECYCLE = "action";
+ public static final String ACTION_PHASE = "action";
/** Denotes a render lifecycle operation. */
- public static final String RENDER_LIFECYCLE = "render";
+ public static final String RENDER_PHASE = "render";
/** Denotes a resource lifecycle operation. */
- public static final String RESOURCE_LIFECYCLE = "resource";
+ public static final String RESOURCE_PHASE = "resource";
}
Modified:
modules/portlet/trunk/test/src/main/java/org/jboss/portal/portlet/test/controller/AbstractPortletControllerContext.java
===================================================================
---
modules/portlet/trunk/test/src/main/java/org/jboss/portal/portlet/test/controller/AbstractPortletControllerContext.java 2008-02-07
18:31:21 UTC (rev 9838)
+++
modules/portlet/trunk/test/src/main/java/org/jboss/portal/portlet/test/controller/AbstractPortletControllerContext.java 2008-02-07
19:11:18 UTC (rev 9839)
@@ -105,6 +105,9 @@
/** . */
private final StateControllerContextImpl stateControllerContext;
+ /** . */
+ private final PageNavigationalState pageState;
+
public AbstractPortletControllerContext(
HttpServletRequest req,
HttpServletResponse resp,
@@ -114,28 +117,29 @@
StateControllerContextImpl tmp = new StateControllerContextImpl(this);
// The nav state provided with the request
+ // Unmarshall portal navigational state if it is provided
PageNavigationalState pageState = null;
+ String context = req.getParameter(PAGE_STATE);
+ if (context != null)
+ {
+ byte[] bytes = Base64.decode(context, true);
+ pageState = tmp.unserialize(bytes, false);
+ }
+ // The type of invocation
+ String type = req.getParameter(TYPE);
+
+ // Process only portlet type
// The request decoded if not null
ControllerRequest request = null;
+ if (PORTLET_TYPE.equals(type))
+ {
+ // Get the window id
+ String windowId = req.getParameter(WINDOW_ID);
- // Get the window id
- String windowId = req.getParameter(WINDOW_ID);
-
- // Process
- if (windowId != null)
- {
// Helper
WebRequest ri = new WebRequest(req);
- // Unmarshall portal navigational state if it is provided
- String context = req.getParameter(PAGE_STATE);
- if (context != null)
- {
- byte[] bytes = Base64.decode(context, true);
- pageState = tmp.unserialize(bytes, false);
- }
-
//
Mode mode = null;
if (req.getParameter(MODE) != null)
@@ -162,8 +166,8 @@
WindowNavigationalState windowNavigationalState = new
WindowNavigationalState(navigationalState, mode, windowState);
//
- String type = req.getParameter(LIFECYCLE_TYPE);
- if (RESOURCE_LIFECYCLE.equals(type))
+ String phase = req.getParameter(LIFECYCLE_PHASE);
+ if (RESOURCE_PHASE.equals(phase))
{
StateString resourceState =
ParametersStateString.create(req.getParameter(RESOURCE_STATE));
String resourceId = req.getParameter(RESOURCE_ID);
@@ -212,7 +216,7 @@
}
else
{
- if (ACTION_LIFECYCLE.equals(type))
+ if (ACTION_PHASE.equals(phase))
{
ParameterMap formParameters = null;
if (ri.getBody() instanceof Body.Form)
@@ -254,8 +258,14 @@
this.resp = resp;
this.servletContext = servletContext;
this.stateControllerContext = tmp;
+ this.pageState = pageState;
}
+ public PageNavigationalState getPageState()
+ {
+ return pageState;
+ }
+
public ControllerRequest getRequest()
{
return request;
Modified:
modules/portlet/trunk/test/src/main/java/org/jboss/portal/portlet/test/controller/PortletURLRenderer.java
===================================================================
---
modules/portlet/trunk/test/src/main/java/org/jboss/portal/portlet/test/controller/PortletURLRenderer.java 2008-02-07
18:31:21 UTC (rev 9838)
+++
modules/portlet/trunk/test/src/main/java/org/jboss/portal/portlet/test/controller/PortletURLRenderer.java 2008-02-07
19:11:18 UTC (rev 9839)
@@ -27,7 +27,6 @@
import org.jboss.portal.common.io.Serialization;
import org.jboss.portal.common.text.CharBuffer;
import org.jboss.portal.common.text.FastURLEncoder;
-import org.jboss.portal.common.util.Tools;
import org.jboss.portal.common.util.Base64;
import org.jboss.portal.portlet.ActionURL;
import org.jboss.portal.portlet.ContainerURL;
@@ -38,14 +37,13 @@
import org.jboss.portal.portlet.cache.CacheLevel;
import org.jboss.portal.portlet.controller.impl.state.StateControllerContextImpl;
import org.jboss.portal.portlet.controller.state.PageNavigationalState;
-import org.jboss.portal.portlet.test.StringCodec;
import static org.jboss.portal.portlet.test.URLParameterConstants.*;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
-import java.io.IOException;
import java.util.HashMap;
import java.util.Map;
+import java.util.Collections;
/**
* @author <a href="mailto:julien@jboss.org">Julien Viet</a>
@@ -58,9 +56,6 @@
final StateControllerContextImpl stateContext;
/** . */
- final String windowId;
-
- /** . */
final HttpServletRequest clientReq;
/** . */
@@ -72,18 +67,16 @@
public PortletURLRenderer(
StateControllerContextImpl stateContext,
PageNavigationalState pageNS,
- String windowId,
HttpServletRequest clientReq,
HttpServletResponse clientResp)
{
this.stateContext = stateContext;
this.pageNS = pageNS;
- this.windowId = windowId;
this.clientReq = clientReq;
this.clientResp = clientResp;
}
- public String renderURL(ContainerURL containerURL, Boolean wantSecure, Boolean
wantAuthenticated, boolean relative)
+ private String renderURL(Map<String, String> parameters, Boolean wantSecure,
Boolean wantAuthenticated, boolean relative)
{
CharBuffer buffer = new CharBuffer();
buffer.append(clientReq.getScheme());
@@ -101,30 +94,68 @@
}
//
+ boolean first = true;
+ for (Map.Entry<String, String> entry : parameters.entrySet())
+ {
+ String name = entry.getKey();
+ String value = entry.getValue();
+ buffer.append(first ? '?' : '&');
+ buffer.append(name, FastURLEncoder.getUTF8Instance());
+ buffer.append('=');
+ buffer.append(value, FastURLEncoder.getUTF8Instance());
+ first = false;
+ }
+
+ //
+ String url = buffer.asString();
+ return clientResp.encodeURL(url);
+ }
+
+ public String renderURL(Boolean wantSecure, Boolean wantAuthenticated, boolean
relative)
+ {
+ String pageState = null;
+ if (pageNS != null)
+ {
+ byte[] bytes = stateContext.serialize(pageNS);
+ pageState = Base64.encodeBytes(bytes, true);
+ }
+
+ //
+ Map<String, String> parameters = Collections.singletonMap(PAGE_STATE,
pageState);
+
+ //
+ return renderURL(parameters, wantSecure, wantAuthenticated, relative);
+ }
+
+ public String renderURL(String windowId, ContainerURL containerURL, Boolean
wantSecure, Boolean wantAuthenticated, boolean relative)
+ {
Map<String, String> parameters = new HashMap<String, String>();
//
+ parameters.put(TYPE, PORTLET_TYPE);
+
+ //
parameters.put(WINDOW_ID, windowId);
//
String type;
if (containerURL instanceof ActionURL)
{
- type = ACTION_LIFECYCLE;
+ type = ACTION_PHASE;
}
else if (containerURL instanceof RenderURL)
{
- type = RENDER_LIFECYCLE;
+ type = RENDER_PHASE;
}
else if (containerURL instanceof ResourceURL)
{
- type = RESOURCE_LIFECYCLE;
+ type = RESOURCE_PHASE;
}
else
{
throw new Error();
}
- parameters.put(LIFECYCLE_TYPE, type);
+ parameters.put(LIFECYCLE_PHASE, type);
//
String pageState = null;
@@ -236,20 +267,6 @@
}
//
- boolean first = true;
- for (Map.Entry<String, String> entry : parameters.entrySet())
- {
- String name = entry.getKey();
- String value = entry.getValue();
- buffer.append(first ? '?' : '&');
- buffer.append(name, FastURLEncoder.getUTF8Instance());
- buffer.append('=');
- buffer.append(value, FastURLEncoder.getUTF8Instance());
- first = false;
- }
-
- //
- String url = buffer.asString();
- return clientResp.encodeURL(url);
+ return renderURL(parameters, wantSecure, wantAuthenticated, relative);
}
}
Modified:
modules/portlet/trunk/test/src/main/java/org/jboss/portal/portlet/test/controller/TestPortletInvocationContext.java
===================================================================
---
modules/portlet/trunk/test/src/main/java/org/jboss/portal/portlet/test/controller/TestPortletInvocationContext.java 2008-02-07
18:31:21 UTC (rev 9838)
+++
modules/portlet/trunk/test/src/main/java/org/jboss/portal/portlet/test/controller/TestPortletInvocationContext.java 2008-02-07
19:11:18 UTC (rev 9839)
@@ -76,7 +76,7 @@
this.clientResponse = clientResponse;
this.windowId = windowId;
this.pageState = pageState;
- this.urlRenderer = new PortletURLRenderer(stateContext, pageState, windowId,
clientRequest, clientResponse);
+ this.urlRenderer = new PortletURLRenderer(stateContext, pageState, clientRequest,
clientResponse);
//
addResolver(PortletInvocation.PRINCIPAL_SCOPE, new
PrincipalAttributeResolver(clientRequest));
@@ -98,6 +98,6 @@
public String renderURL(ContainerURL containerURL, Boolean wantSecure, Boolean
wantAuthenticated, boolean relative)
{
- return urlRenderer.renderURL(containerURL, wantSecure, wantAuthenticated,
relative);
+ return urlRenderer.renderURL(windowId, containerURL, wantSecure, wantAuthenticated,
relative);
}
}
Modified:
modules/portlet/trunk/test/src/main/java/org/jboss/portal/portlet/test/jsp/ControllerFilter.java
===================================================================
---
modules/portlet/trunk/test/src/main/java/org/jboss/portal/portlet/test/jsp/ControllerFilter.java 2008-02-07
18:31:21 UTC (rev 9838)
+++
modules/portlet/trunk/test/src/main/java/org/jboss/portal/portlet/test/jsp/ControllerFilter.java 2008-02-07
19:11:18 UTC (rev 9839)
@@ -42,6 +42,7 @@
import org.jboss.portal.portlet.invocation.response.PortletInvocationResponse;
import org.jboss.portal.portlet.invocation.response.FragmentResponse;
import org.jboss.portal.portlet.controller.PortletController;
+import org.jboss.portal.portlet.controller.request.PortletActionRequest;
import org.jboss.portal.portlet.controller.impl.state.StateControllerContextImpl;
import org.jboss.portal.portlet.controller.response.ControllerResponse;
import org.jboss.portal.portlet.controller.response.PageUpdateResponse;
@@ -154,7 +155,30 @@
if (controllerResponse instanceof PageUpdateResponse)
{
PageUpdateResponse pageUpdate = (PageUpdateResponse)controllerResponse;
- pageState = pageUpdate.getPageState();
+
+ // We perform a send redirect on actions
+ if (context.getRequest() instanceof PortletActionRequest)
+ {
+ //
+ PortletURLRenderer renderer = new PortletURLRenderer(
+ (StateControllerContextImpl)context.getStateControllerContext(),
+ pageState,
+ context.getClientRequest(),
+ context.getClientResponse());
+
+ //
+ String url = renderer.renderURL(null, null, true);
+
+ //
+ resp.sendRedirect(url);
+
+ //
+ return;
+ }
+ else
+ {
+ pageState = pageUpdate.getPageState();
+ }
}
else if (controllerResponse instanceof ResourceResponse)
{
@@ -218,6 +242,10 @@
// todo
}
}
+ else
+ {
+ pageState = context.getPageState();
+ }
//
Page page = context.getPage();
@@ -344,7 +372,6 @@
PortletURLRenderer renderer = new PortletURLRenderer(
(StateControllerContextImpl)context.getStateControllerContext(),
pageState,
- windowId,
context.getClientRequest(),
context.getClientResponse());
@@ -372,7 +399,7 @@
};
//
- String renderedURL = renderer.renderURL(url, null, null, true);
+ String renderedURL = renderer.renderURL(windowId, url, null, null,
true);
writer.write(renderedURL);
writer.flush();
}