Author: alexsmirnov
Date: 2008-01-21 18:07:45 -0500 (Mon, 21 Jan 2008)
New Revision: 5515
Removed:
trunk/extensions/portletbridge/portletbridge-impl/src/main/java/org/ajax4jsf/portlet/WindowIDRetriver.java
Modified:
trunk/extensions/portletbridge/portletbridge-api/src/test/java/javax/portlet/faces/GenericPortletTest.java
trunk/extensions/portletbridge/portletbridge-impl/src/main/java/org/ajax4jsf/portlet/AjaxPortletBridge.java
trunk/extensions/portletbridge/portletbridge-impl/src/main/java/org/ajax4jsf/portlet/application/PortletStateHolder.java
trunk/extensions/portletbridge/portletbridge-impl/src/main/java/org/ajax4jsf/portlet/context/AbstractExternalContext.java
trunk/extensions/portletbridge/portletbridge-impl/src/main/java/org/ajax4jsf/portlet/context/FacesContextImpl.java
trunk/extensions/portletbridge/portletbridge-impl/src/main/java/org/ajax4jsf/portlet/context/PortletExternalContextImpl.java
trunk/extensions/portletbridge/portletbridge-impl/src/test/java/org/ajax4jsf/portlet/application/PortletViewStateTestCase.java
Log:
Start to implement JSF redirect processing in the portlet requests
Modified:
trunk/extensions/portletbridge/portletbridge-api/src/test/java/javax/portlet/faces/GenericPortletTest.java
===================================================================
---
trunk/extensions/portletbridge/portletbridge-api/src/test/java/javax/portlet/faces/GenericPortletTest.java 2008-01-21
20:14:22 UTC (rev 5514)
+++
trunk/extensions/portletbridge/portletbridge-api/src/test/java/javax/portlet/faces/GenericPortletTest.java 2008-01-21
23:07:45 UTC (rev 5515)
@@ -83,7 +83,7 @@
public void testDestroy() throws PortletException, IOException {
setupActionRequest();
GenericFacesPortlet portlet = new GenericFacesPortlet();
- portletContext.setInitParameter("javax.portlet.faces.BridgeClassName",
+ portletContext.setInitParameter("javax.portlet.faces.BridgeImplClass",
MockBridge.class.getName());
portlet.init(portletConfig);
MockBridge facesPortletBrige = (MockBridge) portlet
@@ -108,7 +108,7 @@
portletConfig.addInitParameter("javax.portlet.faces.renderPolicy",
Bridge.BridgeRenderPolicy.NEVER_DELEGATE.toString());
portletConfig.setPortletName("foo");
- portletContext.setInitParameter("javax.portlet.faces.BridgeClassName",
+ portletContext.setInitParameter("javax.portlet.faces.BridgeImplClass",
MockBridge.class.getName());
GenericFacesPortlet portlet = new GenericFacesPortlet();
portlet.init(portletConfig);
@@ -129,7 +129,7 @@
throws PortletException, IOException {
setupRenderRequest();
GenericFacesPortletExtension portlet = new GenericFacesPortletExtension();
- portletContext.setInitParameter("javax.portlet.faces.BridgeClassName",
+ portletContext.setInitParameter("javax.portlet.faces.BridgeImplClass",
MockBridge.class.getName());
portletConfig.addInitParameter(
"javax.portlet.faces.defaultViewId.view", "index.jsf");
@@ -152,7 +152,7 @@
throws PortletException, IOException {
setupRenderRequest();
GenericFacesPortletExtension portlet = new GenericFacesPortletExtension();
- portletContext.setInitParameter("javax.portlet.faces.BridgeClassName",
+ portletContext.setInitParameter("javax.portlet.faces.BridgeImplClass",
MockBridge.class.getName());
portletConfig.addInitParameter(
"javax.portlet.faces.defaultViewId.edit", "index.jsf");
@@ -176,7 +176,7 @@
throws PortletException, IOException {
setupRenderRequest();
GenericFacesPortletExtension portlet = new GenericFacesPortletExtension();
- portletContext.setInitParameter("javax.portlet.faces.BridgeClassName",
+ portletContext.setInitParameter("javax.portlet.faces.BridgeImplClass",
MockBridge.class.getName());
portletConfig.addInitParameter(
"javax.portlet.faces.defaultViewId.view", "index.jsf");
@@ -200,7 +200,7 @@
throws PortletException, IOException {
setupRenderRequest();
GenericFacesPortlet portlet = new GenericFacesPortlet();
- portletContext.setInitParameter("javax.portlet.faces.BridgeClassName",
+ portletContext.setInitParameter("javax.portlet.faces.BridgeImplClass",
MockBridge.class.getName());
portletConfig.addInitParameter(
"javax.portlet.faces.defaultViewId.view", "index.jsf");
@@ -229,7 +229,7 @@
throws PortletException, IOException {
setupRenderRequest();
GenericFacesPortlet portlet = new GenericFacesPortlet();
- portletContext.setInitParameter("javax.portlet.faces.BridgeClassName",
+ portletContext.setInitParameter("javax.portlet.faces.BridgeImplClass",
MockBridge.class.getName());
portletConfig.addInitParameter(
"javax.portlet.faces.defaultViewId.view", "index.jsf");
@@ -249,7 +249,7 @@
throws PortletException, IOException {
setupActionRequest();
GenericFacesPortlet portlet = new GenericFacesPortlet();
- portletContext.setInitParameter("javax.portlet.faces.BridgeClassName",
+ portletContext.setInitParameter("javax.portlet.faces.BridgeImplClass",
MockBridge.class.getName());
portletConfig.addInitParameter(
"javax.portlet.faces.defaultViewId.view", "index.jsf");
@@ -267,7 +267,7 @@
public void testGetBrigeClassName() throws PortletException {
setupActionRequest();
GenericFacesPortlet portlet = new GenericFacesPortlet();
- portletContext.setInitParameter("javax.portlet.faces.BridgeClassName",
+ portletContext.setInitParameter("javax.portlet.faces.BridgeImplClass",
MockBridge.class.getName());
portletContext.setInitParameter(
"javax.portlet.faces.defaultViewId.view", "index.jsf");
@@ -333,7 +333,7 @@
public void testGetDefaultViewId() throws PortletException {
setupActionRequest();
GenericFacesPortlet portlet = new GenericFacesPortlet();
- portletContext.setInitParameter("javax.portlet.faces.BridgeClassName",
+ portletContext.setInitParameter("javax.portlet.faces.BridgeImplClass",
MockBridge.class.getName());
portletConfig.addInitParameter(
"javax.portlet.faces.defaultViewId.view", "index.jsf");
@@ -351,7 +351,7 @@
public void testGetFacesPortletBrige() throws PortletException {
setupActionRequest();
GenericFacesPortlet portlet = new GenericFacesPortlet();
- portletContext.setInitParameter("javax.portlet.faces.BridgeClassName",
+ portletContext.setInitParameter("javax.portlet.faces.BridgeImplClass",
MockBridge.class.getName());
portlet.init(portletConfig);
MockBridge facesPortletBrige = (MockBridge) portlet
Modified:
trunk/extensions/portletbridge/portletbridge-impl/src/main/java/org/ajax4jsf/portlet/AjaxPortletBridge.java
===================================================================
---
trunk/extensions/portletbridge/portletbridge-impl/src/main/java/org/ajax4jsf/portlet/AjaxPortletBridge.java 2008-01-21
20:14:22 UTC (rev 5514)
+++
trunk/extensions/portletbridge/portletbridge-impl/src/main/java/org/ajax4jsf/portlet/AjaxPortletBridge.java 2008-01-21
23:07:45 UTC (rev 5515)
@@ -28,6 +28,7 @@
import org.ajax4jsf.portlet.application.PortletStateHolder;
import org.ajax4jsf.portlet.application.PortletViewState;
import org.ajax4jsf.portlet.context.AbstractExternalContext;
+import org.ajax4jsf.portlet.context.PortletExternalContextImpl;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
@@ -124,7 +125,12 @@
if (!facesContext.getResponseComplete()) {
windowState.saveRequest(facesContext);
- } // saveView(facesContext);
+ } else {
+ String redirectViewId = (String)
facesContext.getExternalContext().getRequestMap().get(AbstractExternalContext.REDIRECT_VIEW_ID);
+ if(null != redirectViewId){
+ windowState.setViewId(redirectViewId);
+ }
+ }
} catch (Exception e) {
// TODO - handle exception.
log.error("Error processing execute lifecycle", e);
@@ -169,6 +175,7 @@
windowState.restoreRequest(facesContext, true);
if (null == facesContext.getViewRoot()) {
execute(facesContext);
+ // TODO - detect redirect case.
}
//
AjaxContext ajaxContext = AjaxContext
@@ -182,13 +189,14 @@
commonAjaxParameters.put(
AbstractExternalContext.NAMESPACE_PARAMETER, namespace);
render(facesContext);
+ // TODO - detect redirect case. Reset response, clear request variables as far as Seam
state.
+ // Perform new render phase with a new ViewId.
+ String redirectViewId = (String)
facesContext.getExternalContext().getRequestMap().get(AbstractExternalContext.REDIRECT_VIEW_ID);
+ if(null != redirectViewId){
+ windowState.setViewId(redirectViewId);
+ }
// writer.println("</div>");
PortletSession portletSession = request.getPortletSession(true);
- // Store namespace value in portlet scope session.
- // ServletContext, in case of ajax requests,
- // will restore session prefiv by it's value.
- portletSession.setAttribute(
- AbstractExternalContext.NAMESPACE_PARAMETER, namespace);
Principal userPrincipal = request.getUserPrincipal();
// TODO - get user roles, defined in the portlet.xml ( ??? parse it ??? ), and store
all values for a "isUserInRole(roleName)" calls
portletSession.setAttribute(AbstractExternalContext.PORTAL_USER_PRINCIPAL,
userPrincipal, PortletSession.APPLICATION_SCOPE);
@@ -227,12 +235,6 @@
request.setAttribute(AbstractExternalContext.PORTLET_CONFIG_ATTRIBUTE,
getPortletConfig());
PortletSession session = request.getPortletSession();
- // Bind WindowIDRetriver to session.
- WindowIDRetriver idRetriver = (WindowIDRetriver)
session.getAttribute(WindowIDRetriver.WINDOW_ID_RETRIVER);
- if(null == idRetriver){
- idRetriver = new WindowIDRetriver();
- session.setAttribute(WindowIDRetriver.WINDOW_ID_RETRIVER, idRetriver);
- }
}
/**
Deleted:
trunk/extensions/portletbridge/portletbridge-impl/src/main/java/org/ajax4jsf/portlet/WindowIDRetriver.java
===================================================================
---
trunk/extensions/portletbridge/portletbridge-impl/src/main/java/org/ajax4jsf/portlet/WindowIDRetriver.java 2008-01-21
20:14:22 UTC (rev 5514)
+++
trunk/extensions/portletbridge/portletbridge-impl/src/main/java/org/ajax4jsf/portlet/WindowIDRetriver.java 2008-01-21
23:07:45 UTC (rev 5515)
@@ -1,62 +0,0 @@
-/**
- *
- */
-package org.ajax4jsf.portlet;
-
-import javax.faces.FacesException;
-import javax.portlet.PortletSession;
-import javax.portlet.PortletSessionUtil;
-import javax.servlet.http.HttpSessionBindingEvent;
-import javax.servlet.http.HttpSessionBindingListener;
-
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
-
-/**
- * Based on the Julien Viet idea.
- * @author asmirnov
- *
- */
-public class WindowIDRetriver implements HttpSessionBindingListener {
-
- private static final String PORTLET_SCOPE_PREFIX = "javax.portlet.p.";
-
- private static final Log log = LogFactory.getLog(WindowIDRetriver.class);
-
- public static final String WINDOW_ID_RETRIVER = WindowIDRetriver.class.getName();
-
- private String windowID;
-
- /* (non-Javadoc)
- * @see
javax.servlet.http.HttpSessionBindingListener#valueBound(javax.servlet.http.HttpSessionBindingEvent)
- */
- public void valueBound(HttpSessionBindingEvent event) {
- String name = event.getName();
- if(null == name || 0 == name.length()){
- throw new FacesException("WindowIDRetriver bind to session without name");
- }
- if( PortletSession.PORTLET_SCOPE != PortletSessionUtil.decodeScope(name)){
- throw new FacesException("WindowIDRetriver bind to APPLICATION_SCOPE.
PORTLET_SCOPE is required");
- }
- windowID = name.substring(PORTLET_SCOPE_PREFIX.length(), name.indexOf('?'));
- if(log.isDebugEnabled()){
- log.debug("WindowIDRetriver have been bind to session for a portlet window
"+windowID);
- }
-
- }
-
- /* (non-Javadoc)
- * @see
javax.servlet.http.HttpSessionBindingListener#valueUnbound(javax.servlet.http.HttpSessionBindingEvent)
- */
- public void valueUnbound(HttpSessionBindingEvent event) {
- // DO nothing.
- }
-
- /**
- * @return the windowID
- */
- String getWindowID() {
- return windowID;
- }
-
-}
Modified:
trunk/extensions/portletbridge/portletbridge-impl/src/main/java/org/ajax4jsf/portlet/application/PortletStateHolder.java
===================================================================
---
trunk/extensions/portletbridge/portletbridge-impl/src/main/java/org/ajax4jsf/portlet/application/PortletStateHolder.java 2008-01-21
20:14:22 UTC (rev 5514)
+++
trunk/extensions/portletbridge/portletbridge-impl/src/main/java/org/ajax4jsf/portlet/application/PortletStateHolder.java 2008-01-21
23:07:45 UTC (rev 5515)
@@ -28,7 +28,6 @@
import javax.servlet.http.HttpSessionBindingListener;
import org.ajax4jsf.portlet.AjaxFacesPortlet;
-import org.ajax4jsf.portlet.WindowIDRetriver;
import org.ajax4jsf.portlet.context.AbstractExternalContext;
import org.ajax4jsf.util.LRUMap;
import org.apache.commons.logging.Log;
@@ -53,8 +52,7 @@
private PortletMode lastMode = PortletMode.VIEW;
- public static final String WINDOW_ID_RETRIVER = WindowIDRetriver.class
- .getName();
+ public static final String WINDOW_ID_RETRIVER =
"org.ajax4jsf.portlet.WINDOW_ID_RETRIVER";
public static final String STATE_ID_PARAMETER =
"javax.faces.portlet.STATE_ID";
@@ -176,7 +174,7 @@
HttpServletRequest servletRequest = (HttpServletRequest) request;
stateId = servletRequest.getParameter(STATE_ID_PARAMETER);
if (null == stateId) {
- throw new FacesException();
+ throw new FacesException("No portlet stateId parameter for AJAX request");
}
} else if (request instanceof PortletRequest) {
PortletRequest portletRequest = (PortletRequest) request;
@@ -207,7 +205,7 @@
UUID uuid = UUID.randomUUID();
stateId = scopeId
- + actionRequest.getPortletMode().toString()
+ + portletModeName
+ uuid.toString();
actionRequest.setAttribute(STATE_ID_PARAMETER, stateId);
ActionResponse response = (ActionResponse) externalContext
Modified:
trunk/extensions/portletbridge/portletbridge-impl/src/main/java/org/ajax4jsf/portlet/context/AbstractExternalContext.java
===================================================================
---
trunk/extensions/portletbridge/portletbridge-impl/src/main/java/org/ajax4jsf/portlet/context/AbstractExternalContext.java 2008-01-21
20:14:22 UTC (rev 5514)
+++
trunk/extensions/portletbridge/portletbridge-impl/src/main/java/org/ajax4jsf/portlet/context/AbstractExternalContext.java 2008-01-21
23:07:45 UTC (rev 5515)
@@ -135,6 +135,7 @@
private Object context;
private boolean hasNavigationRedirect = false;
+ public static final Object REDIRECT_VIEW_ID =
"javax.faces.portlet.REDIRECT_VIEW_ID";
public static final String CONVERSATION_ID_PARAMETER = "conversationId";
/**
Modified:
trunk/extensions/portletbridge/portletbridge-impl/src/main/java/org/ajax4jsf/portlet/context/FacesContextImpl.java
===================================================================
---
trunk/extensions/portletbridge/portletbridge-impl/src/main/java/org/ajax4jsf/portlet/context/FacesContextImpl.java 2008-01-21
20:14:22 UTC (rev 5514)
+++
trunk/extensions/portletbridge/portletbridge-impl/src/main/java/org/ajax4jsf/portlet/context/FacesContextImpl.java 2008-01-21
23:07:45 UTC (rev 5515)
@@ -377,11 +377,11 @@
public void responseComplete() {
checkReleased();
- if (externalContext.isHasNavigationRedirect()) {
- this.renderResponse = true;
- } else {
- this.responseComplete = true;
- }
+// if (externalContext.isHasNavigationRedirect()) {
+// this.renderResponse = true;
+// } else {
+ this.responseComplete = true;
+// }
}
private void checkReleased() {
Modified:
trunk/extensions/portletbridge/portletbridge-impl/src/main/java/org/ajax4jsf/portlet/context/PortletExternalContextImpl.java
===================================================================
---
trunk/extensions/portletbridge/portletbridge-impl/src/main/java/org/ajax4jsf/portlet/context/PortletExternalContextImpl.java 2008-01-21
20:14:22 UTC (rev 5514)
+++
trunk/extensions/portletbridge/portletbridge-impl/src/main/java/org/ajax4jsf/portlet/context/PortletExternalContextImpl.java 2008-01-21
23:07:45 UTC (rev 5515)
@@ -236,7 +236,6 @@
private static final Pattern absoluteUrl = Pattern.compile("");
private static final Pattern directLink = Pattern.compile("");
private static final Pattern viewIdParam = Pattern.compile("");
-
/**
* @param parameters
* @return
@@ -347,12 +346,14 @@
if (null != viewId) {
try {
viewId = URLDecoder.decode(viewId, "UTF8");
- FacesContext facesContext = FacesContext.getCurrentInstance();
- ViewHandler viewHandler = facesContext.getApplication()
- .getViewHandler();
- facesContext.setViewRoot(viewHandler.createView(facesContext,
- viewId));
- setHasNavigationRedirect(true);
+ // Save new viewId to restore after redirect.
+ getRequestMap().put(AbstractExternalContext.REDIRECT_VIEW_ID, viewId);
+// FacesContext facesContext = FacesContext.getCurrentInstance();
+// ViewHandler viewHandler = facesContext.getApplication()
+// .getViewHandler();
+// facesContext.setViewRoot(viewHandler.createView(facesContext,
+// viewId));
+// setHasNavigationRedirect(true);
} catch (UnsupportedEncodingException e) {
// Do nothing - UTF-8 encoding is a default.
}
Modified:
trunk/extensions/portletbridge/portletbridge-impl/src/test/java/org/ajax4jsf/portlet/application/PortletViewStateTestCase.java
===================================================================
---
trunk/extensions/portletbridge/portletbridge-impl/src/test/java/org/ajax4jsf/portlet/application/PortletViewStateTestCase.java 2008-01-21
20:14:22 UTC (rev 5514)
+++
trunk/extensions/portletbridge/portletbridge-impl/src/test/java/org/ajax4jsf/portlet/application/PortletViewStateTestCase.java 2008-01-21
23:07:45 UTC (rev 5515)
@@ -48,7 +48,7 @@
String clientId = input.getClientId(facesContext);
FacesMessage facesMessage = new
FacesMessage(FacesMessage.SEVERITY_ERROR,"msg","detail");
facesContext.addMessage(clientId, facesMessage);
- PortletViewState state = new PortletViewState();
+ PortletViewState state = new PortletViewState("testPortlet012345");
state.saveMessages(facesContext);
Map messages = state.getMessages();
assertEquals(1, messages.size());