Author: alexsmirnov
Date: 2008-01-18 20:48:48 -0500 (Fri, 18 Jan 2008)
New Revision: 5479
Added:
trunk/extensions/portletbridge/portletbridge-api/src/main/java/javax/portlet/faces/annotation/
trunk/extensions/portletbridge/portletbridge-api/src/main/java/javax/portlet/faces/annotation/BridgePreDestroy.java
trunk/extensions/portletbridge/portletbridge-api/src/main/java/javax/portlet/faces/annotation/BridgeRequestScopeAttributeAdded.java
trunk/extensions/portletbridge/portletbridge-api/src/main/java/javax/portlet/faces/annotation/ExcludeFromManagedRequestScope.java
trunk/extensions/portletbridge/portletbridge-api/src/main/java/javax/portlet/faces/annotation/PortletNamingContainer.java
Modified:
trunk/extensions/portletbridge/portletbridge-api/src/main/java/javax/portlet/faces/Bridge.java
trunk/extensions/portletbridge/portletbridge-api/src/main/java/javax/portlet/faces/GenericFacesPortlet.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/application/PortletViewState.java
trunk/extensions/portletbridge/portletbridge-impl/src/main/java/org/ajax4jsf/portlet/context/ServletExternalContextImpl.java
trunk/extensions/portletbridge/portletbridge-impl/src/main/java/org/ajax4jsf/portlet/lifecycle/PortalPhaseListener.java
trunk/samples/ajaxPortlet/src/main/webapp/WEB-INF/.faces-config.xml.jsfdia
trunk/samples/ajaxPortlet/src/main/webapp/WEB-INF/faces-config.xml
Log:
Remove special StateManager for a portlet. Request state saving is a more compatible with
JSR-301
Modified:
trunk/extensions/portletbridge/portletbridge-api/src/main/java/javax/portlet/faces/Bridge.java
===================================================================
---
trunk/extensions/portletbridge/portletbridge-api/src/main/java/javax/portlet/faces/Bridge.java 2008-01-19
01:13:31 UTC (rev 5478)
+++
trunk/extensions/portletbridge/portletbridge-api/src/main/java/javax/portlet/faces/Bridge.java 2008-01-19
01:48:48 UTC (rev 5479)
@@ -96,7 +96,10 @@
* Per-portlet extensions attributes prefix ( this implementation-specific ),
* for additional parameters, as described in the JSR 301 PLT 3.2
*/
- public static final String EXYENDED_PORTLET_ATTR_PREFIX =
"javax.portlet.faces.extension.";
+ public static final String EXTENDED_PORTLET_ATTR_PREFIX =
"javax.portlet.faces.extension.";
+ // allows a portlet to which request attributes the bridge excludes from its
+ // managed request scope.
+ public static final String EXCLUDED_REQUEST_ATTRIBUTES =
"excludedRequestAttributes";
public static final String PRESERVE_ACTION_PARAM_ATTR_SUFFIX =
".preserveActionParams";
public static final String RENDER_POLICY_PARAM_ATTR_SUFFIX = ".renderPolicy";
/**
Modified:
trunk/extensions/portletbridge/portletbridge-api/src/main/java/javax/portlet/faces/GenericFacesPortlet.java
===================================================================
---
trunk/extensions/portletbridge/portletbridge-api/src/main/java/javax/portlet/faces/GenericFacesPortlet.java 2008-01-19
01:13:31 UTC (rev 5478)
+++
trunk/extensions/portletbridge/portletbridge-api/src/main/java/javax/portlet/faces/GenericFacesPortlet.java 2008-01-19
01:48:48 UTC (rev 5479)
@@ -8,11 +8,14 @@
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.UnsupportedEncodingException;
+import java.util.ArrayList;
+import java.util.List;
import javax.portlet.ActionRequest;
import javax.portlet.ActionResponse;
import javax.portlet.GenericPortlet;
import javax.portlet.PortletConfig;
+import javax.portlet.PortletContext;
import javax.portlet.PortletException;
import javax.portlet.PortletMode;
import javax.portlet.PortletRequest;
@@ -30,14 +33,15 @@
public class GenericFacesPortlet extends GenericPortlet {
private static final String BRIDGE_SERVICE_CLASSPATH =
"META-INF/services/javax.portlet.faces.Bridge";
- public static final String BRIDGE_CLASS =
"javax.portlet.faces.BridgeClassName";
+ public static final String BRIDGE_CLASS =
"javax.portlet.faces.BridgeImplClass";
private volatile String bridgeClassName = null;
private volatile Bridge facesPortletBrige = null;
public void init(PortletConfig config) throws PortletException {
super.init(config);
- bridgeClassName = this.getPortletContext().getInitParameter(
+ PortletContext portletContext = this.getPortletContext();
+ bridgeClassName = portletContext.getInitParameter(
BRIDGE_CLASS);
if (bridgeClassName == null) {
ClassLoader loader = getClassLoader();
@@ -75,18 +79,34 @@
if (null == bridgeClassName) {
throw new PortletException("Can't detect bridge implementation class
name");
}
- String renderPolicy =
- this.getPortletConfig().getInitParameter(Bridge.BRIDGE_PACKAGE_PREFIX +
Bridge.RENDER_POLICY);
+ String renderPolicy =
+ config.getInitParameter(Bridge.BRIDGE_PACKAGE_PREFIX +
Bridge.RENDER_POLICY);
if (renderPolicy != null)
- this.getPortletContext().setAttribute(Bridge.BRIDGE_PACKAGE_PREFIX +
+ portletContext.setAttribute(Bridge.BRIDGE_PACKAGE_PREFIX +
this.getPortletName() + "." +
Bridge.RENDER_POLICY,
Bridge.BridgeRenderPolicy.valueOf(renderPolicy));
String preserveActionParams =
- this.getPortletConfig().getInitParameter(Bridge.BRIDGE_PACKAGE_PREFIX +
Bridge.PRESERVE_ACTION_PARAMS);
+ config.getInitParameter(Bridge.BRIDGE_PACKAGE_PREFIX +
Bridge.PRESERVE_ACTION_PARAMS);
if (preserveActionParams != null)
- this.getPortletContext().setAttribute(Bridge.BRIDGE_PACKAGE_PREFIX +
+ portletContext.setAttribute(Bridge.BRIDGE_PACKAGE_PREFIX +
this.getPortletName() + "." +
Bridge.PRESERVE_ACTION_PARAMS,
Boolean.valueOf(preserveActionParams));
+ String excludedAttrs = getPortletConfig()
+ .getInitParameter(
+ Bridge.BRIDGE_PACKAGE_PREFIX
+ + Bridge.EXCLUDED_REQUEST_ATTRIBUTES);
+ if(null != excludedAttrs){
+ String[] atrs = excludedAttrs.split(",");
+ List<String> attrsList = new ArrayList<String>(atrs.length);
+ for (String string : atrs) {
+ attrsList.add(string);
+ }
+ portletContext.setAttribute(
+ Bridge.BRIDGE_PACKAGE_PREFIX + getPortletName() + "."
+ + Bridge.EXCLUDED_REQUEST_ATTRIBUTES,
+ attrsList);
+ }
+
}
protected void doDispatch(RenderRequest request, RenderResponse response)
Added:
trunk/extensions/portletbridge/portletbridge-api/src/main/java/javax/portlet/faces/annotation/BridgePreDestroy.java
===================================================================
---
trunk/extensions/portletbridge/portletbridge-api/src/main/java/javax/portlet/faces/annotation/BridgePreDestroy.java
(rev 0)
+++
trunk/extensions/portletbridge/portletbridge-api/src/main/java/javax/portlet/faces/annotation/BridgePreDestroy.java 2008-01-19
01:48:48 UTC (rev 5479)
@@ -0,0 +1,11 @@
+package javax.portlet.faces.annotation;
+
+import java.lang.annotation.ElementType;
+import java.lang.annotation.Retention;
+import java.lang.annotation.RetentionPolicy;
+import java.lang.annotation.Target;
+
+(a)Retention(RetentionPolicy.RUNTIME)
+(a)Target({ElementType.METHOD})
+public @interface BridgePreDestroy {
+}
Property changes on:
trunk/extensions/portletbridge/portletbridge-api/src/main/java/javax/portlet/faces/annotation/BridgePreDestroy.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Name: svn:keywords
+ Date Revision Author
Added:
trunk/extensions/portletbridge/portletbridge-api/src/main/java/javax/portlet/faces/annotation/BridgeRequestScopeAttributeAdded.java
===================================================================
---
trunk/extensions/portletbridge/portletbridge-api/src/main/java/javax/portlet/faces/annotation/BridgeRequestScopeAttributeAdded.java
(rev 0)
+++
trunk/extensions/portletbridge/portletbridge-api/src/main/java/javax/portlet/faces/annotation/BridgeRequestScopeAttributeAdded.java 2008-01-19
01:48:48 UTC (rev 5479)
@@ -0,0 +1,12 @@
+package javax.portlet.faces.annotation;
+
+import java.lang.annotation.ElementType;
+import java.lang.annotation.Retention;
+import java.lang.annotation.RetentionPolicy;
+import java.lang.annotation.Target;
+
+(a)Retention(RetentionPolicy.RUNTIME)
+(a)Target({ElementType.METHOD})
+public @interface BridgeRequestScopeAttributeAdded {
+}
+
Property changes on:
trunk/extensions/portletbridge/portletbridge-api/src/main/java/javax/portlet/faces/annotation/BridgeRequestScopeAttributeAdded.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Name: svn:keywords
+ Date Revision Author
Added:
trunk/extensions/portletbridge/portletbridge-api/src/main/java/javax/portlet/faces/annotation/ExcludeFromManagedRequestScope.java
===================================================================
---
trunk/extensions/portletbridge/portletbridge-api/src/main/java/javax/portlet/faces/annotation/ExcludeFromManagedRequestScope.java
(rev 0)
+++
trunk/extensions/portletbridge/portletbridge-api/src/main/java/javax/portlet/faces/annotation/ExcludeFromManagedRequestScope.java 2008-01-19
01:48:48 UTC (rev 5479)
@@ -0,0 +1,11 @@
+package javax.portlet.faces.annotation;
+
+import java.lang.annotation.ElementType;
+import java.lang.annotation.Retention;
+import java.lang.annotation.RetentionPolicy;
+import java.lang.annotation.Target;
+
+(a)Retention(RetentionPolicy.RUNTIME)
+(a)Target({ElementType.TYPE})
+public @interface ExcludeFromManagedRequestScope {
+}
Property changes on:
trunk/extensions/portletbridge/portletbridge-api/src/main/java/javax/portlet/faces/annotation/ExcludeFromManagedRequestScope.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Name: svn:keywords
+ Date Revision Author
Added:
trunk/extensions/portletbridge/portletbridge-api/src/main/java/javax/portlet/faces/annotation/PortletNamingContainer.java
===================================================================
---
trunk/extensions/portletbridge/portletbridge-api/src/main/java/javax/portlet/faces/annotation/PortletNamingContainer.java
(rev 0)
+++
trunk/extensions/portletbridge/portletbridge-api/src/main/java/javax/portlet/faces/annotation/PortletNamingContainer.java 2008-01-19
01:48:48 UTC (rev 5479)
@@ -0,0 +1,11 @@
+package javax.portlet.faces.annotation;
+
+import java.lang.annotation.ElementType;
+import java.lang.annotation.Retention;
+import java.lang.annotation.RetentionPolicy;
+import java.lang.annotation.Target;
+
+(a)Retention(RetentionPolicy.RUNTIME)
+(a)Target({ElementType.TYPE})
+public @interface PortletNamingContainer {
+}
Property changes on:
trunk/extensions/portletbridge/portletbridge-api/src/main/java/javax/portlet/faces/annotation/PortletNamingContainer.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Name: svn:keywords
+ Date Revision Author
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-19
01:13:31 UTC (rev 5478)
+++
trunk/extensions/portletbridge/portletbridge-impl/src/main/java/org/ajax4jsf/portlet/AjaxPortletBridge.java 2008-01-19
01:48:48 UTC (rev 5479)
@@ -70,6 +70,7 @@
PortletContext portletContext = config.getPortletContext();
synchronized (portletContext) {
init();
+ PortletStateHolder.init(portletContext);
}
} catch (FacesException e) {
throw new PortletException("Initialization error", e);
@@ -177,13 +178,9 @@
commonAjaxParameters.put(AbstractExternalContext.ACTION__PARAMETER,
facesContext.getExternalContext().encodeActionURL(actionURL));
commonAjaxParameters.put(
- AbstractExternalContext.PORTLET_MODE_PARAMETER, request
- .getPortletMode().toString());
+ PortletStateHolder.STATE_ID_PARAMETER, windowState.getStateId());
commonAjaxParameters.put(
AbstractExternalContext.NAMESPACE_PARAMETER, namespace);
- commonAjaxParameters.put(
- AbstractExternalContext.PORTLET_NAME_PARAMETER,
- getPortletConfig().getPortletName());
render(facesContext);
// writer.println("</div>");
PortletSession portletSession = request.getPortletSession(true);
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-19
01:13:31 UTC (rev 5478)
+++
trunk/extensions/portletbridge/portletbridge-impl/src/main/java/org/ajax4jsf/portlet/application/PortletStateHolder.java 2008-01-19
01:48:48 UTC (rev 5479)
@@ -5,22 +5,40 @@
import java.io.Serializable;
import java.util.Map;
+import java.util.UUID;
+import javax.faces.FacesException;
import javax.faces.context.ExternalContext;
import javax.faces.context.FacesContext;
+import javax.portlet.ActionRequest;
+import javax.portlet.ActionResponse;
+import javax.portlet.PortletConfig;
+import javax.portlet.PortletContext;
import javax.portlet.PortletMode;
import javax.portlet.PortletRequest;
+import javax.portlet.PortletSession;
+import javax.portlet.PortletSessionUtil;
+import javax.portlet.RenderRequest;
+import javax.portlet.RenderResponse;
import javax.portlet.faces.Bridge;
import javax.portlet.faces.BridgeDefaultViewNotSpecifiedException;
+import javax.portlet.faces.BridgeException;
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpSessionBindingEvent;
+import javax.servlet.http.HttpSessionBindingListener;
import org.ajax4jsf.portlet.AjaxFacesPortlet;
-import org.apache.commons.collections.map.LRUMap;
+import org.ajax4jsf.portlet.WindowIDRetriver;
+import org.ajax4jsf.portlet.context.AbstractExternalContext;
+import org.ajax4jsf.util.LRUMap;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
/**
* @author asmirnov
*
*/
-public class PortletStateHolder implements Serializable {
+public class PortletStateHolder {
/**
*
*/
@@ -29,17 +47,23 @@
private static final String STATE_HOLDER = PortletStateHolder.class
.getName();
- private static final String[] modes = { PortletMode.VIEW.toString(),
- PortletMode.EDIT.toString(), PortletMode.HELP.toString() };
-
private static final String DEFAULT = "default-";
+ private static final Log log = LogFactory.getLog(PortletStateHolder.class);
+
private PortletMode lastMode = PortletMode.VIEW;
+ public static final String WINDOW_ID_RETRIVER = WindowIDRetriver.class
+ .getName();
+
+ public static final String STATE_ID_PARAMETER =
"javax.faces.portlet.STATE_ID";
+
+ private static final int DEFAULT_MAX_MANAGED_SCOPES = 1000;
+
/**
* View states for a different portlet modes, Views and serial numbers.
*/
- private Map states = new LRUMap();
+ private Map<String, PortletViewState> states;
/**
* Private constructor - instance must be stored in the session, and created
@@ -47,9 +71,27 @@
*
* @param context
*/
- private PortletStateHolder() {
+ private PortletStateHolder(int max) {
+ states = new LRUMap<String, PortletViewState>(max);
}
+ public static void init(PortletContext context) {
+ synchronized (context) {
+ PortletStateHolder stateHolder = (PortletStateHolder) context
+ .getAttribute(STATE_HOLDER);
+ if (null == stateHolder) {
+ int maxScopes = DEFAULT_MAX_MANAGED_SCOPES;
+ String maxScopesParameter = context
+ .getInitParameter(Bridge.MAX_MANAGED_REQUEST_SCOPES);
+ if (null != maxScopesParameter) {
+ maxScopes = Integer.parseInt(maxScopesParameter);
+ }
+ context.setAttribute(STATE_HOLDER, new PortletStateHolder(
+ maxScopes));
+ }
+ }
+ }
+
/**
* Get instance of portlet states, stored in the session. If no previsious
* instance in session, create default value.
@@ -59,23 +101,12 @@
*/
public static PortletStateHolder getInstance(FacesContext context) {
ExternalContext externalContext = context.getExternalContext();
- Object session = externalContext.getSession(true);
- Map sessionMap = externalContext.getSessionMap();
- PortletStateHolder instance = null;
- synchronized (session) {
- instance = (PortletStateHolder) sessionMap.get(STATE_HOLDER);
- if (null == instance) {
- // Create and store in session new state holder.
- instance = new PortletStateHolder();
- Object request = externalContext.getRequest();
- if (request instanceof PortletRequest) {
- PortletRequest portletRequest = (PortletRequest) request;
- instance.setLastMode(portletRequest.getPortletMode());
- }
- sessionMap.put(STATE_HOLDER, instance);
- }
+ PortletStateHolder stateHolder = (PortletStateHolder) externalContext
+ .getApplicationMap().get(STATE_HOLDER);
+ if (null == stateHolder) {
+ throw new BridgeException("Jsf portlet bridge not initialised");
}
- return instance;
+ return stateHolder;
}
/**
@@ -97,10 +128,12 @@
// If none of above happen, try to get default viewId for a current
// mode.
if (null == viewId) {
- viewId = (String)
context.getExternalContext().getRequestMap().get(Bridge.DEFAULT_VIEWID);
+ viewId = (String) context.getExternalContext().getRequestMap().get(
+ Bridge.DEFAULT_VIEWID);
}
if (null == viewId) {
- throw new BridgeDefaultViewNotSpecifiedException("could'n determine portlet
view id");
+ throw new BridgeDefaultViewNotSpecifiedException(
+ "could'n determine portlet view id");
}
return viewId;
}
@@ -112,102 +145,175 @@
* @return
*/
public PortletViewState getWindowState(FacesContext context) {
- PortletMode portletMode = AjaxFacesPortlet.getPortletMode(context);
- if (null == portletMode) {
- portletMode = lastMode;
+ String stateId = getStateId(context);
+ PortletViewState state;
+ synchronized (states) {
+ state = (PortletViewState) states.get(stateId);
+ if (null == state) {
+ state = new PortletViewState(stateId);
+ states.put(stateId, state);
+ }
}
- StateKey windowKey = new StateKey(portletMode);
- PortletViewState state = (PortletViewState) states.get(windowKey);
- if (null == state) {
- state = new PortletViewState();
- states.put(windowKey, state);
- }
return state;
}
+ private void removeSessionStates(String scoprId) {
+ synchronized (states) {
+ for (String key : states.keySet()) {
+ if (key.startsWith(scoprId)) {
+ states.remove(key);
+ }
+ }
+
+ }
+ }
+
+ public String getStateId(FacesContext context) {
+ ExternalContext externalContext = context.getExternalContext();
+ Object request = externalContext.getRequest();
+ String stateId;
+ if (request instanceof HttpServletRequest) {
+ HttpServletRequest servletRequest = (HttpServletRequest) request;
+ stateId = servletRequest.getParameter(STATE_ID_PARAMETER);
+ if (null == stateId) {
+ throw new FacesException();
+ }
+ } else if (request instanceof PortletRequest) {
+ PortletRequest portletRequest = (PortletRequest) request;
+ PortletSession portletSession = portletRequest
+ .getPortletSession(true);
+ PortletConfig portletConfig = (PortletConfig) portletRequest
+ .getAttribute(AbstractExternalContext.PORTLET_CONFIG_ATTRIBUTE);
+ if (null == portletConfig) {
+ throw new FacesException();
+ }
+ String scopeId = portletConfig.getPortletName()
+ + portletSession.getId();
+ String portletModeName = portletRequest.getPortletMode().toString();
+ if (request instanceof RenderRequest) {
+ RenderRequest renderRequest = (RenderRequest) request;
+ stateId = renderRequest.getParameter(STATE_ID_PARAMETER);
+ if (null == stateId) {
+ RenderResponse response = (RenderResponse) externalContext
+ .getResponse();
+ stateId = scopeId + portletModeName
+ + response.getNamespace();
+ }
+ } else if (request instanceof ActionRequest) {
+ ActionRequest actionRequest = (ActionRequest) request;
+ stateId = (String) actionRequest
+ .getAttribute(STATE_ID_PARAMETER);
+ if (null == stateId) {
+
+ UUID uuid = UUID.randomUUID();
+ stateId = scopeId
+ + actionRequest.getPortletMode().toString()
+ + uuid.toString();
+ actionRequest.setAttribute(STATE_ID_PARAMETER, stateId);
+ ActionResponse response = (ActionResponse) externalContext
+ .getResponse();
+ response.setRenderParameter(STATE_ID_PARAMETER, stateId);
+ }
+ } else {
+ throw new FacesException();
+ }
+ WindowIDRetriver idRetriver =
(org.ajax4jsf.portlet.application.PortletStateHolder.WindowIDRetriver) portletSession
+ .getAttribute(WINDOW_ID_RETRIVER);
+ if (null == idRetriver) {
+ idRetriver = new WindowIDRetriver(scopeId);
+ portletSession.setAttribute(WINDOW_ID_RETRIVER, idRetriver);
+ }
+ } else {
+ throw new FacesException();
+ }
+ return stateId;
+ }
+
/**
+ * @return the lastMode
+ */
+ public PortletMode getLastMode() {
+ return lastMode;
+ }
+
+ /**
+ * @param lastMode
+ * the lastMode to set
+ */
+ public void setLastMode(PortletMode lastMode) {
+ this.lastMode = lastMode;
+ }
+
+ /**
+ * Based on the Julien Viet idea.
+ *
* @author asmirnov
*
*/
- private static class StateKey implements Serializable {
- /**
- *
- */
- private static final long serialVersionUID = -1490104706512592990L;
+ public final class WindowIDRetriver implements HttpSessionBindingListener {
- private PortletMode mode;
+ public static final String PORTLET_SCOPE_PREFIX = "javax.portlet.p.";
- private String namespace;
-
-
+ private final String scopeId;
- public StateKey(PortletMode mode) {
- super();
- this.mode = mode;
- }
+ private String windowID;
/**
- * @param mode
- * @param namespace
+ * @param scopeId
*/
- public StateKey(PortletMode mode, String namespace) {
- this.mode = mode;
- this.namespace = namespace;
+ private WindowIDRetriver(String scopeId) {
+ this.scopeId = scopeId;
}
/*
* (non-Javadoc)
*
- * @see java.lang.Object#hashCode()
+ * @see
javax.servlet.http.HttpSessionBindingListener#valueBound(javax.servlet.http.HttpSessionBindingEvent)
*/
- public int hashCode() {
- final int PRIME = 31;
- int result = 1;
- result = PRIME * result + ((mode == null) ? 0 : mode.hashCode());
- result = PRIME * result
- + ((namespace == null) ? 0 : namespace.hashCode());
- return result;
+ 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 java.lang.Object#equals(java.lang.Object)
+ * @see
javax.servlet.http.HttpSessionBindingListener#valueUnbound(javax.servlet.http.HttpSessionBindingEvent)
*/
- public boolean equals(Object obj) {
- if (this == obj)
- return true;
- if (obj == null)
- return false;
- if (getClass() != obj.getClass())
- return false;
- final StateKey other = (StateKey) obj;
- if (mode == null) {
- if (other.mode != null)
- return false;
- } else if (!mode.equals(other.mode))
- return false;
- if (namespace == null) {
- if (other.namespace != null)
- return false;
- } else if (!namespace.equals(other.namespace))
- return false;
- return true;
+ public void valueUnbound(HttpSessionBindingEvent event) {
+ removeSessionStates(scopeId);
}
- }
+ /**
+ * @return the windowID
+ */
+ public String getWindowID() {
+ return windowID;
+ }
- /**
- * @return the lastMode
- */
- public PortletMode getLastMode() {
- return lastMode;
+ /**
+ * @return the scopeId
+ */
+ public String getScopeId() {
+ return scopeId;
+ }
+
}
- /**
- * @param lastMode the lastMode to set
- */
- public void setLastMode(PortletMode lastMode) {
- this.lastMode = lastMode;
- }
}
Modified:
trunk/extensions/portletbridge/portletbridge-impl/src/main/java/org/ajax4jsf/portlet/application/PortletViewState.java
===================================================================
---
trunk/extensions/portletbridge/portletbridge-impl/src/main/java/org/ajax4jsf/portlet/application/PortletViewState.java 2008-01-19
01:13:31 UTC (rev 5478)
+++
trunk/extensions/portletbridge/portletbridge-impl/src/main/java/org/ajax4jsf/portlet/application/PortletViewState.java 2008-01-19
01:48:48 UTC (rev 5479)
@@ -75,7 +75,20 @@
private Map<String, String[]> _requestParameters;
+ private final String stateId;
+
+ public PortletViewState(String stateId) {
+ this.stateId = stateId;
+ }
+
/**
+ * @return the stateId
+ */
+ public String getStateId() {
+ return stateId;
+ }
+
+ /**
* @return the viewId
*/
public String getViewId() {
Modified:
trunk/extensions/portletbridge/portletbridge-impl/src/main/java/org/ajax4jsf/portlet/context/ServletExternalContextImpl.java
===================================================================
---
trunk/extensions/portletbridge/portletbridge-impl/src/main/java/org/ajax4jsf/portlet/context/ServletExternalContextImpl.java 2008-01-19
01:13:31 UTC (rev 5478)
+++
trunk/extensions/portletbridge/portletbridge-impl/src/main/java/org/ajax4jsf/portlet/context/ServletExternalContextImpl.java 2008-01-19
01:48:48 UTC (rev 5479)
@@ -31,6 +31,8 @@
import org.ajax4jsf.context.AjaxContext;
import org.ajax4jsf.portlet.AjaxPortletBridge;
+import org.ajax4jsf.portlet.application.PortletStateHolder;
+import org.ajax4jsf.portlet.application.PortletStateHolder.WindowIDRetriver;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
@@ -229,27 +231,27 @@
private String getSessionPrefix() {
if (sessionPrefix == null) {
HttpSession session = getHttpRequest().getSession(false);
- String namespase = getNamespace();
- if (null == namespase || null == session) {
+ String scopeId =
getHttpRequest().getParameter(PortletStateHolder.STATE_ID_PARAMETER);
+ if (null == scopeId || null == session) {
throw new FacesException(
- "JSF request called without portlet namespace parameter");
+ "JSF request called without portlet state parameter");
}
Enumeration attributeNames = session.getAttributeNames();
while (attributeNames.hasMoreElements() && null == sessionPrefix) {
String name = (String) attributeNames.nextElement();
- Object attribute = session.getAttribute(name);
if (PortletSessionUtil.decodeScope(name) == PortletSession.PORTLET_SCOPE
&& PortletSessionUtil.decodeAttributeName(name).equals(
- NAMESPACE_PARAMETER)
- && namespase.equals(attribute)) {
- sessionPrefix = name.substring(0, name.length()
- - NAMESPACE_PARAMETER.length());
+ PortletStateHolder.WINDOW_ID_RETRIVER)) {
+ PortletStateHolder.WindowIDRetriver attribute = (WindowIDRetriver)
session.getAttribute(name);
+ if (scopeId.startsWith(attribute.getScopeId())) {
+ sessionPrefix =
WindowIDRetriver.PORTLET_SCOPE_PREFIX+attribute.getWindowID()+'?';
if (_log.isDebugEnabled()) {
_log
.debug("Prefix for a PORTLET_SCOPE session attributes: "
+ sessionPrefix);
}
- }
+
+ } }
}
if (null == sessionPrefix) {
throw new FacesException(
Modified:
trunk/extensions/portletbridge/portletbridge-impl/src/main/java/org/ajax4jsf/portlet/lifecycle/PortalPhaseListener.java
===================================================================
---
trunk/extensions/portletbridge/portletbridge-impl/src/main/java/org/ajax4jsf/portlet/lifecycle/PortalPhaseListener.java 2008-01-19
01:13:31 UTC (rev 5478)
+++
trunk/extensions/portletbridge/portletbridge-impl/src/main/java/org/ajax4jsf/portlet/lifecycle/PortalPhaseListener.java 2008-01-19
01:48:48 UTC (rev 5479)
@@ -3,6 +3,7 @@
*/
package org.ajax4jsf.portlet.lifecycle;
+import java.net.MalformedURLException;
import java.util.Map;
import javax.faces.context.FacesContext;
@@ -15,6 +16,7 @@
import org.ajax4jsf.portlet.application.PortletStateHolder;
import org.ajax4jsf.portlet.application.PortletViewState;
import org.ajax4jsf.portlet.context.AbstractExternalContext;
+import org.ajax4jsf.portlet.context.PortalActionURL;
/**
* @author asmirnov
@@ -57,44 +59,44 @@
*
* @see javax.faces.event.PhaseListener#beforePhase(javax.faces.event.PhaseEvent)
*/
+ @SuppressWarnings("unchecked")
public void beforePhase(PhaseEvent event) {
PhaseId phaseId = event.getPhaseId();
FacesContext context = event.getFacesContext();
Object portletPhase = context.getExternalContext().getRequestMap().get(
Bridge.PORTLET_LIFECYCLE_PHASE);
if (null == portletPhase && phaseId.equals(PhaseId.RENDER_RESPONSE)) {
- // For a servlet phase, put all portlet-related parameters
- // back to ajaxContext.
- Map<String, String> requestParameters = context
- .getExternalContext().getRequestParameterMap();
+ // For a servlet phase, put all portlet-related parameters
+ // back to ajaxContext.
+ Map<String, String> requestParameters = context
+ .getExternalContext().getRequestParameterMap();
- AjaxContext ajaxContext = AjaxContext
- .getCurrentInstance(context);
- Map commonAjaxParameters = ajaxContext
- .getCommonAjaxParameters();
- commonAjaxParameters
- .put(
- AbstractExternalContext.ACTION__PARAMETER,
- requestParameters
- .get(AbstractExternalContext.ACTION__PARAMETER));
- commonAjaxParameters
- .put(
- AbstractExternalContext.PORTLET_MODE_PARAMETER,
- requestParameters
- .get(AbstractExternalContext.PORTLET_MODE_PARAMETER));
+ AjaxContext ajaxContext = AjaxContext.getCurrentInstance(context);
+ Map commonAjaxParameters = ajaxContext.getCommonAjaxParameters();
+ String portalActionUrl = requestParameters
+ .get(AbstractExternalContext.ACTION__PARAMETER);
+ if (null != portalActionUrl) {
+ try {
+ PortalActionURL pal = new PortalActionURL(portalActionUrl);
+ pal.addParameter(AbstractExternalContext.VIEW_ID_PARAMETER,
+ context.getViewRoot().getViewId());
+ commonAjaxParameters.put(
+ AbstractExternalContext.ACTION__PARAMETER, pal
+ .toString());
- commonAjaxParameters
- .put(
- AbstractExternalContext.NAMESPACE_PARAMETER,
- requestParameters
- .get(AbstractExternalContext.NAMESPACE_PARAMETER));
+ } catch (MalformedURLException e) {
+ // TODO: log exception ?
+ }
+ }
+ commonAjaxParameters.put(
+ AbstractExternalContext.NAMESPACE_PARAMETER,
+ requestParameters
+ .get(AbstractExternalContext.NAMESPACE_PARAMETER));
- commonAjaxParameters
- .put(
- AbstractExternalContext.PORTLET_NAME_PARAMETER,
- requestParameters
- .get(AbstractExternalContext.PORTLET_NAME_PARAMETER));
- }
+ commonAjaxParameters.put(PortletStateHolder.STATE_ID_PARAMETER,
+ requestParameters
+ .get(PortletStateHolder.STATE_ID_PARAMETER));
+ }
}
/*
Modified: trunk/samples/ajaxPortlet/src/main/webapp/WEB-INF/.faces-config.xml.jsfdia
===================================================================
--- trunk/samples/ajaxPortlet/src/main/webapp/WEB-INF/.faces-config.xml.jsfdia 2008-01-19
01:13:31 UTC (rev 5478)
+++ trunk/samples/ajaxPortlet/src/main/webapp/WEB-INF/.faces-config.xml.jsfdia 2008-01-19
01:48:48 UTC (rev 5479)
@@ -18,4 +18,40 @@
TARGET="rules:#jsf#start.xhtml" TITLE="start"/>
</PROCESS-ITEM>
</PROCESS-ITEM>
+ <PROCESS-ITEM ENTITY="JSFProcessGroup"
NAME="rules:#jsf#help.jspx"
+ PATH="/jsf/help.jspx" SHAPE="240,145,0,0">
+ <PROCESS-ITEM ENTITY="JSFProcessItem"
ID="rules:#jsf#help.jspx:0"
+ NAME="item" PATH="/jsf/help.jspx">
+ <PROCESS-ITEM-OUTPUT ENTITY="JSFProcessItemOutput"
+ ID="help2::#jsf#help2.jspx" NAME="output"
PATH="/jsf/help2.jspx"
+ TARGET="rules:#jsf#help2.jspx" TITLE="help2"/>
+ </PROCESS-ITEM>
+ </PROCESS-ITEM>
+ <PROCESS-ITEM ENTITY="JSFProcessGroup"
NAME="rules:#jsf#help2.jspx"
+ PATH="/jsf/help2.jspx" SHAPE="32,129,0,0">
+ <PROCESS-ITEM ENTITY="JSFProcessItem"
ID="rules:#jsf#help2.jspx:0"
+ NAME="item" PATH="/jsf/help2.jspx">
+ <PROCESS-ITEM-OUTPUT ENTITY="JSFProcessItemOutput"
+ ID="start::#jsf#help.jspx" NAME="output"
PATH="/jsf/help.jspx"
+ TARGET="rules:#jsf#help.jspx" TITLE="start"/>
+ </PROCESS-ITEM>
+ </PROCESS-ITEM>
+ <PROCESS-ITEM ENTITY="JSFProcessGroup"
NAME="rules:#jsf#edit.jspx"
+ PATH="/jsf/edit.jspx" SHAPE="240,257,0,0">
+ <PROCESS-ITEM ENTITY="JSFProcessItem"
ID="rules:#jsf#edit.jspx:0"
+ NAME="item" PATH="/jsf/edit.jspx">
+ <PROCESS-ITEM-OUTPUT ENTITY="JSFProcessItemOutput"
+ ID="edit2::#jsf#edit2.jspx" NAME="output"
PATH="/jsf/edit2.jspx"
+ TARGET="rules:#jsf#edit2.jspx" TITLE="edit2"/>
+ </PROCESS-ITEM>
+ </PROCESS-ITEM>
+ <PROCESS-ITEM ENTITY="JSFProcessGroup"
NAME="rules:#jsf#edit2.jspx"
+ PATH="/jsf/edit2.jspx" SHAPE="32,241,0,0">
+ <PROCESS-ITEM ENTITY="JSFProcessItem"
ID="rules:#jsf#edit2.jspx:0"
+ NAME="item" PATH="/jsf/edit2.jspx">
+ <PROCESS-ITEM-OUTPUT ENTITY="JSFProcessItemOutput"
+ ID="start::#jsf#edit.jspx" NAME="output"
PATH="/jsf/edit.jspx"
+ TARGET="rules:#jsf#edit.jspx" TITLE="start"/>
+ </PROCESS-ITEM>
+ </PROCESS-ITEM>
</PROCESS>
Modified: trunk/samples/ajaxPortlet/src/main/webapp/WEB-INF/faces-config.xml
===================================================================
--- trunk/samples/ajaxPortlet/src/main/webapp/WEB-INF/faces-config.xml 2008-01-19 01:13:31
UTC (rev 5478)
+++ trunk/samples/ajaxPortlet/src/main/webapp/WEB-INF/faces-config.xml 2008-01-19 01:48:48
UTC (rev 5479)
@@ -70,10 +70,10 @@
<view-handler>
org.ajax4jsf.portlet.application.PortletViewHandler
</view-handler>
+ <!--
<state-manager>
org.ajax4jsf.portlet.application.PortalStateManager
</state-manager>
- <!--
<view-handler>com.sun.facelets.FaceletPortletViewHandler</view-handler>
-->
</application>