[richfaces-svn-commits] JBoss Rich Faces SVN: r5657 - in branches/3.1.x: extensions/portletbridge/portletbridge-api and 15 other directories.

richfaces-svn-commits at lists.jboss.org richfaces-svn-commits at lists.jboss.org
Fri Jan 25 20:04:53 EST 2008


Author: alexsmirnov
Date: 2008-01-25 20:04:53 -0500 (Fri, 25 Jan 2008)
New Revision: 5657

Added:
   branches/3.1.x/extensions/portletbridge/portletbridge-impl/src/main/java/org/ajax4jsf/portlet/lifecycle/PortletLifecycle.java
   branches/3.1.x/extensions/portletbridge/portletbridge-impl/src/main/java/org/ajax4jsf/portlet/lifecycle/SeamPortletLifecycle.java
   branches/3.1.x/extensions/portletbridge/portletbridge-impl/src/main/java/org/ajax4jsf/portlet/seam/ConversationIdRetriver.java
   branches/3.1.x/extensions/portletbridge/portletbridge-impl/src/main/java/org/jboss/
   branches/3.1.x/extensions/portletbridge/portletbridge-impl/src/main/java/org/jboss/seam/
   branches/3.1.x/extensions/portletbridge/portletbridge-impl/src/main/java/org/jboss/seam/jsf/
   branches/3.1.x/extensions/portletbridge/portletbridge-impl/src/main/java/org/jboss/seam/jsf/SeamPhaseListenerWrapper.java
   branches/3.1.x/extensions/portletbridge/portletbridge-impl/src/main/resources/META-INF/.faces-config.xml.jsfdia
Removed:
   branches/3.1.x/extensions/portletbridge/portletbridge-impl/src/main/java/org/ajax4jsf/portlet/lifecycle/PortletLifecycle.java
   branches/3.1.x/extensions/portletbridge/portletbridge-impl/src/main/java/org/ajax4jsf/util/
   branches/3.1.x/extensions/portletbridge/portletbridge-impl/src/main/java/org/jboss/seam/
   branches/3.1.x/extensions/portletbridge/portletbridge-impl/src/main/java/org/jboss/seam/jsf/
   branches/3.1.x/extensions/portletbridge/portletbridge-impl/src/main/java/org/jboss/seam/jsf/SeamPhaseListenerWrapper.java
Modified:
   branches/3.1.x/extensions/portletbridge/pom.xml
   branches/3.1.x/extensions/portletbridge/portletbridge-api/pom.xml
   branches/3.1.x/extensions/portletbridge/portletbridge-impl/pom.xml
   branches/3.1.x/extensions/portletbridge/portletbridge-impl/src/main/java/org/ajax4jsf/portlet/AjaxPortletBridge.java
   branches/3.1.x/extensions/portletbridge/portletbridge-impl/src/main/java/org/ajax4jsf/portlet/application/PortletStateHolder.java
   branches/3.1.x/extensions/portletbridge/portletbridge-impl/src/main/java/org/ajax4jsf/portlet/application/PortletViewState.java
   branches/3.1.x/extensions/portletbridge/portletbridge-impl/src/main/java/org/ajax4jsf/portlet/context/RenderPortletExternalContextImpl.java
   branches/3.1.x/extensions/portletbridge/portletbridge-impl/src/main/java/org/ajax4jsf/portlet/context/ServletExternalContextImpl.java
   branches/3.1.x/extensions/portletbridge/portletbridge-impl/src/main/java/org/ajax4jsf/portlet/lifecycle/PortalPhaseListener.java
   branches/3.1.x/extensions/portletbridge/portletbridge-impl/src/main/java/org/ajax4jsf/portlet/lifecycle/PortletLifecycleFactory.java
   branches/3.1.x/extensions/portletbridge/portletbridge-impl/src/main/java/org/ajax4jsf/portlet/seam/SeamPhaseListener.java
   branches/3.1.x/extensions/portletbridge/portletbridge-impl/src/main/resources/META-INF/faces-config.xml
   branches/3.1.x/extensions/portletbridge/portletbridge-impl/src/test/java/org/ajax4jsf/portlet/context/PortletExternalContextTest.java
   branches/3.1.x/framework/impl/src/main/java/org/ajax4jsf/application/AjaxStateManager.java
   branches/3.1.x/framework/impl/src/main/java/org/ajax4jsf/context/AjaxContextImpl.java
Log:
merge portlet bridge from trunk

Modified: branches/3.1.x/extensions/portletbridge/pom.xml
===================================================================
--- branches/3.1.x/extensions/portletbridge/pom.xml	2008-01-26 00:38:11 UTC (rev 5656)
+++ branches/3.1.x/extensions/portletbridge/pom.xml	2008-01-26 01:04:53 UTC (rev 5657)
@@ -10,18 +10,6 @@
 	<version>3.1.4-SNAPSHOT</version>
   <name>Richfaces bridge for a portlet environment</name>
   <packaging>pom</packaging>
-	<build>
-		<plugins>
-			<plugin>
-				<groupId>org.apache.maven.plugins</groupId>
-				<artifactId>maven-compiler-plugin</artifactId>
-				<configuration>
-					<source>1.5</source>
-					<target>1.5</target>
-				</configuration>
-			</plugin>
-		</plugins>
-	</build>
    <repositories>
       <repository>
          <releases>
@@ -39,6 +27,18 @@
          <layout>default</layout>
       </repository>
    </repositories>
+	<build>
+		<plugins>
+			<plugin>
+				<groupId>org.apache.maven.plugins</groupId>
+				<artifactId>maven-compiler-plugin</artifactId>
+				<configuration>
+					<source>1.5</source>
+					<target>1.5</target>
+				</configuration>
+			</plugin>
+		</plugins>
+	</build>
 	<dependencies>
 		<dependency>
 			<groupId>junit</groupId>

Modified: branches/3.1.x/extensions/portletbridge/portletbridge-api/pom.xml
===================================================================
--- branches/3.1.x/extensions/portletbridge/portletbridge-api/pom.xml	2008-01-26 00:38:11 UTC (rev 5656)
+++ branches/3.1.x/extensions/portletbridge/portletbridge-api/pom.xml	2008-01-26 01:04:53 UTC (rev 5657)
@@ -25,15 +25,6 @@
          </execution>
        </executions>
      </plugin>
-	<plugin>
-		<groupId>org.apache.maven.plugins</groupId>
-		<artifactId>maven-surefire-plugin</artifactId>
-		<configuration>
-			<excludes>
-				<exclude>**/AbstractAjax4jsfPortletTestCase.java</exclude>
-			</excludes>
-		</configuration>
-	</plugin>
     </plugins>
   </build>
 </project>
\ No newline at end of file

Modified: branches/3.1.x/extensions/portletbridge/portletbridge-impl/pom.xml
===================================================================
--- branches/3.1.x/extensions/portletbridge/portletbridge-impl/pom.xml	2008-01-26 00:38:11 UTC (rev 5656)
+++ branches/3.1.x/extensions/portletbridge/portletbridge-impl/pom.xml	2008-01-26 01:04:53 UTC (rev 5657)
@@ -40,7 +40,7 @@
 		<dependency>
 			<groupId>org.jboss.seam</groupId>
 			<artifactId>jboss-seam</artifactId>
-			<version>2.0.1.CR2</version>
+			<version>2.0.0.GA</version>
 			<optional>true</optional>
 		</dependency>
 		<dependency>

Modified: branches/3.1.x/extensions/portletbridge/portletbridge-impl/src/main/java/org/ajax4jsf/portlet/AjaxPortletBridge.java
===================================================================
--- branches/3.1.x/extensions/portletbridge/portletbridge-impl/src/main/java/org/ajax4jsf/portlet/AjaxPortletBridge.java	2008-01-26 00:38:11 UTC (rev 5656)
+++ branches/3.1.x/extensions/portletbridge/portletbridge-impl/src/main/java/org/ajax4jsf/portlet/AjaxPortletBridge.java	2008-01-26 01:04:53 UTC (rev 5657)
@@ -14,6 +14,7 @@
 
 import javax.faces.FacesException;
 import javax.faces.context.FacesContext;
+import javax.faces.lifecycle.Lifecycle;
 import javax.portlet.ActionRequest;
 import javax.portlet.ActionResponse;
 import javax.portlet.PortletConfig;
@@ -79,6 +80,8 @@
 			synchronized (portletContext) {
 				init();
 				PortletStateHolder.init(portletContext);
+				Lifecycle lifecycle = getLifecycle();
+				lifecycle.getPhaseListeners();
 			}
 		} catch (FacesException e) {
 			throw new PortletException("Initialization error", e);

Modified: branches/3.1.x/extensions/portletbridge/portletbridge-impl/src/main/java/org/ajax4jsf/portlet/application/PortletStateHolder.java
===================================================================
--- branches/3.1.x/extensions/portletbridge/portletbridge-impl/src/main/java/org/ajax4jsf/portlet/application/PortletStateHolder.java	2008-01-26 00:38:11 UTC (rev 5656)
+++ branches/3.1.x/extensions/portletbridge/portletbridge-impl/src/main/java/org/ajax4jsf/portlet/application/PortletStateHolder.java	2008-01-26 01:04:53 UTC (rev 5657)
@@ -148,12 +148,14 @@
 	 */
 	public PortletViewState getWindowState(FacesContext context) {
 		String stateId = getStateId(context);
-		PortletViewState state;
-		synchronized (states) {
-			state = getWindowState(stateId);
-			if (null == state) {
-				state = new PortletViewState(stateId);
-				states.put(stateId, state);
+		PortletViewState state = null;
+		if (null != stateId) {
+			synchronized (states) {
+				state = getWindowState(stateId);
+				if (null == state) {
+					state = new PortletViewState(stateId);
+					states.put(stateId, state);
+				}
 			}
 		}
 		return state;
@@ -164,8 +166,10 @@
 	 * @return
 	 */
 	public PortletViewState getWindowState(String stateId) {
-		PortletViewState state;
+		PortletViewState state = null;
+		if (null != stateId) {
 			state = (PortletViewState) states.get(stateId);
+		}
 		return state;
 	}
 
@@ -189,9 +193,9 @@
 		if (request instanceof HttpServletRequest) {
 			HttpServletRequest servletRequest = (HttpServletRequest) request;
 			stateId = servletRequest.getParameter(STATE_ID_PARAMETER);
-			if (null == stateId) {
-				throw new FacesException("No portlet stateId parameter for AJAX request");
-			}
+//			if (null == stateId) {
+//				throw new FacesException("No portlet stateId parameter for AJAX request");
+//			}
 		} else if (request instanceof PortletRequest) {
 			PortletRequest portletRequest = (PortletRequest) request;
 			PortletSession portletSession = portletRequest

Modified: branches/3.1.x/extensions/portletbridge/portletbridge-impl/src/main/java/org/ajax4jsf/portlet/application/PortletViewState.java
===================================================================
--- branches/3.1.x/extensions/portletbridge/portletbridge-impl/src/main/java/org/ajax4jsf/portlet/application/PortletViewState.java	2008-01-26 00:38:11 UTC (rev 5656)
+++ branches/3.1.x/extensions/portletbridge/portletbridge-impl/src/main/java/org/ajax4jsf/portlet/application/PortletViewState.java	2008-01-26 01:04:53 UTC (rev 5657)
@@ -24,12 +24,26 @@
 import org.ajax4jsf.context.AjaxContext;
 import org.ajax4jsf.portlet.context.AbstractExternalContext;
 import org.ajax4jsf.portlet.context.PortalActionURL;
+import org.ajax4jsf.portlet.seam.ConversationIdRetriver;
+import org.ajax4jsf.renderkit.AjaxContainerRenderer;
 
 /**
  * @author asmirnov
  * 
  */
 public class PortletViewState implements Serializable {
+	
+	private static ConversationIdRetriver conversationIdRetriver;
+	
+	static {
+		try {
+			conversationIdRetriver = new ConversationIdRetriver();
+		} catch(NoClassDefFoundError e){
+			// Do nothing, no seam classes available.
+			String message = e.getMessage();
+			conversationIdRetriver = null;
+		}
+	}
 
 	/**
 	 * 
@@ -86,7 +100,12 @@
 	private final String stateId;
 	
 	private String windowId;
+	
+	private String conversationIdParameter="conversationId";
+	
+	private String conversationId;
 
+
 	/**
 	 * @param stateId
 	 */
@@ -254,7 +273,8 @@
 	 */
 	public void saveBeans(FacesContext facesContext) {
 		beans = null;
-		Map<String, Object> requestMap = facesContext.getExternalContext()
+		ExternalContext externalContext = facesContext.getExternalContext();
+		Map<String, Object> requestMap = externalContext
 				.getRequestMap();
 		List existingAttributes = (List) requestMap
 				.get(AbstractExternalContext.EXCLUDED_PARAMETERS_ATTRIBUTE);
@@ -286,8 +306,22 @@
 				beans.put(attributeName, entry.getValue());
 			}
 		}
-		requestParameters = new HashMap<String, String[]>(facesContext
-				.getExternalContext().getRequestParameterValuesMap());
+		// Save request parameters ( all or a View state only ) restored as requered
+		// in the JSR 301 PLT 5.1
+		String preserveActionParamAttr = externalContext.getInitParameter(Bridge.BRIDGE_PACKAGE_PREFIX+Bridge.PRESERVE_ACTION_PARAMS);
+		if(null != preserveActionParamAttr && "true".equalsIgnoreCase(preserveActionParamAttr)){
+			requestParameters = new HashMap<String, String[]>(externalContext.getRequestParameterValuesMap());
+			requestParameters.remove(AjaxContainerRenderer.AJAX_PARAMETER_NAME);
+		} else {
+			requestParameters = new HashMap<String, String[]>();
+			String[] viewStateParam = externalContext
+					.getRequestParameterValuesMap().get(
+							ResponseStateManager.VIEW_STATE_PARAM);
+			if (null != viewStateParam && viewStateParam.length > 0) {
+				requestParameters.put(ResponseStateManager.VIEW_STATE_PARAM,
+						viewStateParam);
+			}
+		}
 		saveSeamConversationId(facesContext);
 	}
 
@@ -296,25 +330,8 @@
 	 */
 	public void saveSeamConversationId(FacesContext facesContext) {
 		// Seam hack - save conversation Id for a request parameter.
-		try {
-			Application application = facesContext.getApplication();
-			Object isLongRunningConversation = application
-			.evaluateExpressionGet(facesContext, "#{conversation.longRunning}",
-					Boolean.class);
-			if (Boolean.TRUE.equals(isLongRunningConversation)) {
-				Object conversationId = application.evaluateExpressionGet(
-						facesContext, "#{conversation.id}", Object.class);
-				if (null != conversationId) {
-					requestParameters.put(
-							AbstractExternalContext.CONVERSATION_ID_PARAMETER,
-							new String[] { conversationId.toString() });
-				}
-
-			} else {
-				requestParameters.remove(AbstractExternalContext.CONVERSATION_ID_PARAMETER);
-			}
-		} catch (Exception e) {
-			// Do nothing - no seam conversation found !
+		if(null != conversationIdRetriver) {
+			conversationIdRetriver.setConversationIdParameter(this);
 		}
 	}
 
@@ -324,9 +341,16 @@
 		if (null != beans) {
 			requestMap.putAll(beans);
 		}
+		HashMap<String, String[]> parameters;
 		if (null != requestParameters) {
-			requestMap.put(REQUEST_PARAMETERS_ATTRIBUTE, requestParameters);
+			parameters = new HashMap<String, String[]>(requestParameters);
+		} else {
+			parameters = new HashMap<String, String[]>();
 		}
+		if(null != conversationId){
+			parameters.put(conversationIdParameter, new String[]{conversationId});
+		}
+		requestMap.put(REQUEST_PARAMETERS_ATTRIBUTE, parameters);
 	}
 
 	public void restoreRequest(FacesContext facesContext, boolean b) {
@@ -421,6 +445,35 @@
 		this.treeStructure=null;
 		this.viewRoot=null;
 		this.viewId=null;
+		this.conversationId=null;
 	}
+	
+	/**
+	 * @return the conversationIdParameter
+	 */
+	public String getConversationIdParameter() {
+		return conversationIdParameter;
+	}
 
+	/**
+	 * @param conversationIdParameter the conversationIdParameter to set
+	 */
+	public void setConversationIdParameter(String conversationIdParameter) {
+		this.conversationIdParameter = conversationIdParameter;
+	}
+
+	/**
+	 * @return the conversationId
+	 */
+	public String getConversationId() {
+		return conversationId;
+	}
+
+	/**
+	 * @param conversationId the conversationId to set
+	 */
+	public void setConversationId(String conversationId) {
+		this.conversationId = conversationId;
+	}
+
 }

Modified: branches/3.1.x/extensions/portletbridge/portletbridge-impl/src/main/java/org/ajax4jsf/portlet/context/RenderPortletExternalContextImpl.java
===================================================================
--- branches/3.1.x/extensions/portletbridge/portletbridge-impl/src/main/java/org/ajax4jsf/portlet/context/RenderPortletExternalContextImpl.java	2008-01-26 00:38:11 UTC (rev 5656)
+++ branches/3.1.x/extensions/portletbridge/portletbridge-impl/src/main/java/org/ajax4jsf/portlet/context/RenderPortletExternalContextImpl.java	2008-01-26 01:04:53 UTC (rev 5657)
@@ -143,31 +143,7 @@
 		if (null == _requestParameters) {
 			// Get parameters ( all or a View state only ) restored as requered
 			// in the JSR 301 PLT 5.1
-			Object preserveRequestAttr = Boolean.FALSE;
-			PortletConfig portletConfig = (PortletConfig) getRequestAttribute(PORTLET_CONFIG_ATTRIBUTE);
-			if (null != portletConfig) {
-				String portletPreserveParamName = Bridge.PORTLET_ATTR_PREFIX
-						+ portletConfig.getPortletName()
-						+ Bridge.PRESERVE_ACTION_PARAM_ATTR_SUFFIX;
-				preserveRequestAttr = getContextAttribute(portletPreserveParamName);
-			}
-			Map<String, String[]> parameters = (Map<String, String[]>) getRequestAttribute(PortletViewState.REQUEST_PARAMETERS_ATTRIBUTE);
-			if (Boolean.TRUE.equals(preserveRequestAttr)) {
-				_requestParameters = parameters;
-			} else if (null != parameters) {
-				_requestParameters = new HashMap<String, String[]>();
-				String[] viewState = parameters
-						.get(ResponseStateManager.VIEW_STATE_PARAM);
-				if (null != viewState) {
-					_requestParameters.put(
-							ResponseStateManager.VIEW_STATE_PARAM, viewState);
-
-				}
-				String[] conversationId = parameters.get(CONVERSATION_ID_PARAMETER);
-				if(null != conversationId){
-					_requestParameters.put(CONVERSATION_ID_PARAMETER, conversationId);
-				}
-			}
+			_requestParameters = (Map<String, String[]>) getRequestAttribute(PortletViewState.REQUEST_PARAMETERS_ATTRIBUTE);
 		}
 		return _requestParameters;
 	}

Modified: branches/3.1.x/extensions/portletbridge/portletbridge-impl/src/main/java/org/ajax4jsf/portlet/context/ServletExternalContextImpl.java
===================================================================
--- branches/3.1.x/extensions/portletbridge/portletbridge-impl/src/main/java/org/ajax4jsf/portlet/context/ServletExternalContextImpl.java	2008-01-26 00:38:11 UTC (rev 5656)
+++ branches/3.1.x/extensions/portletbridge/portletbridge-impl/src/main/java/org/ajax4jsf/portlet/context/ServletExternalContextImpl.java	2008-01-26 01:04:53 UTC (rev 5657)
@@ -58,6 +58,8 @@
 		ArrayList excludedAttributes = Collections.list(request
 				.getAttributeNames());
 		request.setAttribute(EXCLUDED_PARAMETERS_ATTRIBUTE, excludedAttributes);
+		namespace="";
+		sessionPrefix="";
 		PortletStateHolder portletStateHolder = (PortletStateHolder) context
 				.getAttribute(PortletStateHolder.STATE_HOLDER);
 		if (null != portletStateHolder) {
@@ -71,9 +73,6 @@
 						+ windowState.getWindowId() + '?';
 				portalActionUrl = windowState.getPortalActionURL();
 			}
-		} else {
-			namespace="";
-			sessionPrefix="";
 		}
 	}
 

Modified: branches/3.1.x/extensions/portletbridge/portletbridge-impl/src/main/java/org/ajax4jsf/portlet/lifecycle/PortalPhaseListener.java
===================================================================
--- branches/3.1.x/extensions/portletbridge/portletbridge-impl/src/main/java/org/ajax4jsf/portlet/lifecycle/PortalPhaseListener.java	2008-01-26 00:38:11 UTC (rev 5656)
+++ branches/3.1.x/extensions/portletbridge/portletbridge-impl/src/main/java/org/ajax4jsf/portlet/lifecycle/PortalPhaseListener.java	2008-01-26 01:04:53 UTC (rev 5657)
@@ -37,8 +37,8 @@
 	public void afterPhase(PhaseEvent event) {
 		PhaseId phaseId = event.getPhaseId();
 		FacesContext context = event.getFacesContext();
-		Object portletPhase = context.getExternalContext().getRequestMap()
-		.get(Bridge.PORTLET_LIFECYCLE_PHASE);
+		Object portletPhase = context.getExternalContext().getRequestMap().get(
+				Bridge.PORTLET_LIFECYCLE_PHASE);
 		if (phaseId.equals(PhaseId.RESTORE_VIEW)) {
 			if (Bridge.PortletPhase.RenderPhase.equals(portletPhase)) {
 				context.renderResponse();
@@ -46,14 +46,24 @@
 		} else if (phaseId.equals(PhaseId.RENDER_RESPONSE)) {
 			// save Seam conversation Id.
 			PortletViewState windowState = PortletStateHolder.getInstance(
-					context).getWindowState(context);	
-			windowState.saveSeamConversationId(context);
-		} else if (null == portletPhase && (phaseId.equals(PhaseId.INVOKE_APPLICATION)
-				&& context.getRenderResponse())) {
-			// save request scope variables and Faces Messages for a Servlet request.
+					context).getWindowState(context);
+			if (null != windowState) {
+				windowState.saveSeamConversationId(context);
+			}
+		} else if (phaseId.equals(PhaseId.INVOKE_APPLICATION)
+				|| context.getRenderResponse() || context.getResponseComplete()) {
+			// save request scope variables and Faces Messages for a Servlet
+			// request.
 			PortletViewState windowState = PortletStateHolder.getInstance(
 					context).getWindowState(context);
-			windowState.saveRequest(context);
+			if (null != windowState) {
+				if (null == portletPhase) {
+					windowState.saveRequest(context);
+				} else if (Bridge.PortletPhase.ActionPhase.equals(portletPhase)) {
+					windowState.saveSeamConversationId(context);
+				}
+
+			}
 		}
 
 	}
@@ -77,8 +87,10 @@
 
 			AjaxContext ajaxContext = AjaxContext.getCurrentInstance(context);
 			Map commonAjaxParameters = ajaxContext.getCommonAjaxParameters();
-			PortletStateHolder portletStateHolder = PortletStateHolder.getInstance(context);
-			String stateId = requestParameters.get(PortletStateHolder.STATE_ID_PARAMETER);
+			PortletStateHolder portletStateHolder = PortletStateHolder
+					.getInstance(context);
+			String stateId = requestParameters
+					.get(PortletStateHolder.STATE_ID_PARAMETER);
 			// Change viewId parameter in the portal action URL.
 			PortletViewState windowState = portletStateHolder
 					.getWindowState(stateId);

Deleted: branches/3.1.x/extensions/portletbridge/portletbridge-impl/src/main/java/org/ajax4jsf/portlet/lifecycle/PortletLifecycle.java
===================================================================
--- branches/3.1.x/extensions/portletbridge/portletbridge-impl/src/main/java/org/ajax4jsf/portlet/lifecycle/PortletLifecycle.java	2008-01-26 00:38:11 UTC (rev 5656)
+++ branches/3.1.x/extensions/portletbridge/portletbridge-impl/src/main/java/org/ajax4jsf/portlet/lifecycle/PortletLifecycle.java	2008-01-26 01:04:53 UTC (rev 5657)
@@ -1,134 +0,0 @@
-/**
- * 
- */
-package org.ajax4jsf.portlet.lifecycle;
-
-import java.io.Serializable;
-import java.util.ArrayList;
-import java.util.HashMap;
-import java.util.Iterator;
-import java.util.List;
-import java.util.Map;
-import java.util.Map.Entry;
-
-import javax.faces.FacesException;
-import javax.faces.context.FacesContext;
-import javax.faces.event.PhaseListener;
-import javax.faces.lifecycle.Lifecycle;
-import javax.portlet.PortletRequest;
-
-import org.ajax4jsf.portlet.application.PortletStateHolder;
-import org.ajax4jsf.portlet.application.PortletViewState;
-
-/**
- * @author asmirnov
- *
- */
-public class PortletLifecycle extends Lifecycle {
-	
-	//List<PhaseListener>
-	private final List _phaseListeners = new ArrayList();
-	
-	private final LifecyclePhase executePhase = new RestoreViewPhase(this);
-	
-	private final LifecyclePhase renderPhase = new RenderResponsePhase(this);
-	
-	private PhaseListener[] _phaseListenersArray = null;
-    
-    public PortletLifecycle() {
-    }
-
-    /**
-     * @param listener
-     * @see javax.faces.lifecycle.Lifecycle#addPhaseListener(javax.faces.event.PhaseListener)
-     */
-    public void addPhaseListener(PhaseListener listener) {
-		if(null == listener){
-			throw new NullPointerException("PhaseListener for add to Lifecycle can't be null");
-		}
-		synchronized (_phaseListeners) {
-			_phaseListeners.add(listener);
-			_phaseListenersArray = null;
-		}
-    }
-
- 
-    /**
-	 * @param listener
-	 * @see javax.faces.lifecycle.Lifecycle#removePhaseListener(javax.faces.event.PhaseListener)
-	 */
-	public void removePhaseListener(PhaseListener listener) {
-		if(null == listener){
-			throw new NullPointerException("PhaseListener for remove from Lifecycle can't be null");
-		}
-		synchronized (_phaseListeners) {
-			_phaseListeners.remove(listener);
-			_phaseListenersArray = null;
-		}
-	}
-
-	/**
-	 * @return
-	 * @see javax.faces.lifecycle.Lifecycle#getPhaseListeners()
-	 */
-	public PhaseListener[] getPhaseListeners() {
-		if (_phaseListenersArray == null) {
-			// Lazy creation of a working copy listeners Array.
-			synchronized (_phaseListeners) {
-				_phaseListenersArray = (PhaseListener[]) _phaseListeners.toArray(new PhaseListener[_phaseListeners.size()]);				
-			}			
-		}
-	
-		return _phaseListenersArray;
-	}
-
-	/**
-     * @param context
-     * @throws FacesException
-     * @see javax.faces.lifecycle.Lifecycle#execute(javax.faces.context.FacesContext)
-     */
-    public void execute(FacesContext context) throws FacesException {
-	    executePhase.execute(context);
-	    // TODO - in the portlet mode, save state
-//	    Object request = context.getExternalContext().getRequest();
-//	    if(request instanceof PortletRequest){
-//	    	context.getApplication().getStateManager().saveSerializedView(context);
-//	    }
-//	    // TODO - save request scope variables and Faces Messages.
-//    	PortletViewState windowState = PortletStateHolder.getInstance(context).getWindowState(context);
-//    	windowState.saveMessages(context);
-//    	HashMap requestScopeBeans = new HashMap();
-//    	for (Iterator iterator = context.getExternalContext().getRequestMap().entrySet().iterator(); iterator.hasNext();) {	
-//			Entry entry = (Entry) iterator.next();
-//			String paramName = entry.getKey().toString();
-//			Object bean = entry.getValue();
-//			if(!paramName.contains(".") && bean instanceof Serializable){
-//				requestScopeBeans.put(paramName, bean);
-//			}
-//		}
-//    	if(requestScopeBeans.size()>0){
-//    		windowState.setRequestScopeBeans(requestScopeBeans);
-//    	}
-    }
-
-    /**
-     * @param context
-     * @throws FacesException
-     * @see javax.faces.lifecycle.Lifecycle#render(javax.faces.context.FacesContext)
-     */
-    public void render(FacesContext context) throws FacesException {
-	    // TODO - in the portlet mode, restore state, request scope variables and Faces Messages.
-//	    Object request = context.getExternalContext().getRequest();
-//	    if(request instanceof PortletRequest){
-//	    	executePhase.executePhase(context);
-//	    	PortletViewState windowState = PortletStateHolder.getInstance(context).getWindowState(context);
-//	    	windowState.restoreMessages(context);
-//	    	Map requestScopeBeans = windowState.getRequestScopeBeans();
-//	    	if(null != requestScopeBeans){
-//	    		context.getExternalContext().getRequestMap().putAll(requestScopeBeans);
-//	    	}
-//	    }
-		renderPhase.execute(context);
-    }
-    
-}

Copied: branches/3.1.x/extensions/portletbridge/portletbridge-impl/src/main/java/org/ajax4jsf/portlet/lifecycle/PortletLifecycle.java (from rev 5656, trunk/extensions/portletbridge/portletbridge-impl/src/main/java/org/ajax4jsf/portlet/lifecycle/PortletLifecycle.java)
===================================================================
--- branches/3.1.x/extensions/portletbridge/portletbridge-impl/src/main/java/org/ajax4jsf/portlet/lifecycle/PortletLifecycle.java	                        (rev 0)
+++ branches/3.1.x/extensions/portletbridge/portletbridge-impl/src/main/java/org/ajax4jsf/portlet/lifecycle/PortletLifecycle.java	2008-01-26 01:04:53 UTC (rev 5657)
@@ -0,0 +1,147 @@
+/**
+ * 
+ */
+package org.ajax4jsf.portlet.lifecycle;
+
+import java.io.Serializable;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
+import java.util.Map.Entry;
+
+import javax.faces.FacesException;
+import javax.faces.context.FacesContext;
+import javax.faces.event.PhaseListener;
+import javax.faces.lifecycle.Lifecycle;
+import javax.portlet.PortletRequest;
+
+import org.ajax4jsf.portlet.application.PortletStateHolder;
+import org.ajax4jsf.portlet.application.PortletViewState;
+
+/**
+ * @author asmirnov
+ *
+ */
+public class PortletLifecycle extends Lifecycle {
+	
+	//List<PhaseListener>
+	private final List<PhaseListener> _phaseListeners = new ArrayList<PhaseListener>();
+	
+	private final LifecyclePhase executePhase = new RestoreViewPhase(this);
+	
+	private final LifecyclePhase renderPhase = new RenderResponsePhase(this);
+	
+	private PhaseListener[] _phaseListenersArray = null;
+    
+    public PortletLifecycle() {
+    }
+
+    /**
+     * @param listener
+     * @see javax.faces.lifecycle.Lifecycle#addPhaseListener(javax.faces.event.PhaseListener)
+     */
+    public void addPhaseListener(PhaseListener listener) {
+		if(null == listener){
+			throw new NullPointerException("PhaseListener for add to Lifecycle can't be null");
+		}
+		synchronized (_phaseListeners) {
+			_phaseListeners.add(listener);
+			_phaseListenersArray = null;
+		}
+    }
+
+    /**
+     * @param listener
+     * @see javax.faces.lifecycle.Lifecycle#addPhaseListener(javax.faces.event.PhaseListener)
+     */
+    protected void addPhaseListener(int index, PhaseListener listener) {
+		if(null == listener){
+			throw new NullPointerException("PhaseListener for add to Lifecycle can't be null");
+		}
+		synchronized (_phaseListeners) {
+			_phaseListeners.add(index, listener);
+			_phaseListenersArray = null;
+		}
+    }
+ 
+    /**
+	 * @param listener
+	 * @see javax.faces.lifecycle.Lifecycle#removePhaseListener(javax.faces.event.PhaseListener)
+	 */
+	public void removePhaseListener(PhaseListener listener) {
+		if(null == listener){
+			throw new NullPointerException("PhaseListener for remove from Lifecycle can't be null");
+		}
+		synchronized (_phaseListeners) {
+			_phaseListeners.remove(listener);
+			_phaseListenersArray = null;
+		}
+	}
+
+	/**
+	 * @return
+	 * @see javax.faces.lifecycle.Lifecycle#getPhaseListeners()
+	 */
+	public PhaseListener[] getPhaseListeners() {
+		if (_phaseListenersArray == null) {
+			// Lazy creation of a working copy listeners Array.
+			synchronized (_phaseListeners) {
+				_phaseListenersArray = (PhaseListener[]) _phaseListeners.toArray(new PhaseListener[_phaseListeners.size()]);				
+			}			
+		}
+	
+		return _phaseListenersArray;
+	}
+
+	/**
+     * @param context
+     * @throws FacesException
+     * @see javax.faces.lifecycle.Lifecycle#execute(javax.faces.context.FacesContext)
+     */
+    public void execute(FacesContext context) throws FacesException {
+	    executePhase.execute(context);
+	    // TODO - in the portlet mode, save state
+//	    Object request = context.getExternalContext().getRequest();
+//	    if(request instanceof PortletRequest){
+//	    	context.getApplication().getStateManager().saveSerializedView(context);
+//	    }
+//	    // TODO - save request scope variables and Faces Messages.
+//    	PortletViewState windowState = PortletStateHolder.getInstance(context).getWindowState(context);
+//    	windowState.saveMessages(context);
+//    	HashMap requestScopeBeans = new HashMap();
+//    	for (Iterator iterator = context.getExternalContext().getRequestMap().entrySet().iterator(); iterator.hasNext();) {	
+//			Entry entry = (Entry) iterator.next();
+//			String paramName = entry.getKey().toString();
+//			Object bean = entry.getValue();
+//			if(!paramName.contains(".") && bean instanceof Serializable){
+//				requestScopeBeans.put(paramName, bean);
+//			}
+//		}
+//    	if(requestScopeBeans.size()>0){
+//    		windowState.setRequestScopeBeans(requestScopeBeans);
+//    	}
+    }
+
+    /**
+     * @param context
+     * @throws FacesException
+     * @see javax.faces.lifecycle.Lifecycle#render(javax.faces.context.FacesContext)
+     */
+    public void render(FacesContext context) throws FacesException {
+	    // TODO - in the portlet mode, restore state, request scope variables and Faces Messages.
+//	    Object request = context.getExternalContext().getRequest();
+//	    if(request instanceof PortletRequest){
+//	    	executePhase.executePhase(context);
+//	    	PortletViewState windowState = PortletStateHolder.getInstance(context).getWindowState(context);
+//	    	windowState.restoreMessages(context);
+//	    	Map requestScopeBeans = windowState.getRequestScopeBeans();
+//	    	if(null != requestScopeBeans){
+//	    		context.getExternalContext().getRequestMap().putAll(requestScopeBeans);
+//	    	}
+//	    }
+		renderPhase.execute(context);
+    }
+    
+}

Modified: branches/3.1.x/extensions/portletbridge/portletbridge-impl/src/main/java/org/ajax4jsf/portlet/lifecycle/PortletLifecycleFactory.java
===================================================================
--- branches/3.1.x/extensions/portletbridge/portletbridge-impl/src/main/java/org/ajax4jsf/portlet/lifecycle/PortletLifecycleFactory.java	2008-01-26 00:38:11 UTC (rev 5656)
+++ branches/3.1.x/extensions/portletbridge/portletbridge-impl/src/main/java/org/ajax4jsf/portlet/lifecycle/PortletLifecycleFactory.java	2008-01-26 01:04:53 UTC (rev 5657)
@@ -37,8 +37,6 @@
 	
 	private LifecycleFactory _defaultFactory;
 	
-	//Map<String, Lifecycle>
-	private final Map _lifecycles = new HashMap(1);
 	
 //	private Map _lifecycles = new HashMap();
 
@@ -49,34 +47,39 @@
 	public PortletLifecycleFactory(LifecycleFactory defaultFactory) {
 		super();
 		this._defaultFactory = defaultFactory;
-		this._lifecycles.put(DEFAULT_LIFECYCLE, new PortletLifecycle());
+		this._defaultFactory.addLifecycle(
+				SeamPortletLifecycle.SEAM_PORTLET_LIFECYCLE,
+				new SeamPortletLifecycle());
 	}
 
-	/* (non-Javadoc)
+
+	/**
+	 * @param lifecycleId
+	 * @param lifecycle
 	 * @see javax.faces.lifecycle.LifecycleFactory#addLifecycle(java.lang.String, javax.faces.lifecycle.Lifecycle)
 	 */
 	public void addLifecycle(String lifecycleId, Lifecycle lifecycle) {
-		if(null == lifecycleId || null == lifecycle){
-			throw new NullPointerException("arguments for a addLifecycle method can't be null");
-		}
-		_lifecycles.put(lifecycleId, lifecycle);
+		_defaultFactory.addLifecycle(lifecycleId, lifecycle);
 	}
 
-	/* (non-Javadoc)
+
+	/**
+	 * @param lifecycleId
+	 * @return
 	 * @see javax.faces.lifecycle.LifecycleFactory#getLifecycle(java.lang.String)
 	 */
 	public Lifecycle getLifecycle(String lifecycleId) {
-		if(null == lifecycleId ){
-			throw new NullPointerException("argument for a removeLifecycle method can't be null");
-		}
-		return (Lifecycle) _lifecycles.get(lifecycleId);
+		return _defaultFactory.getLifecycle(lifecycleId);
 	}
 
-	/* (non-Javadoc)
+
+	/**
+	 * @return
 	 * @see javax.faces.lifecycle.LifecycleFactory#getLifecycleIds()
 	 */
-	public Iterator getLifecycleIds() {
-		return _lifecycles.keySet().iterator();
+	public Iterator<String> getLifecycleIds() {
+		return _defaultFactory.getLifecycleIds();
 	}
 
+
 }

Copied: branches/3.1.x/extensions/portletbridge/portletbridge-impl/src/main/java/org/ajax4jsf/portlet/lifecycle/SeamPortletLifecycle.java (from rev 5656, trunk/extensions/portletbridge/portletbridge-impl/src/main/java/org/ajax4jsf/portlet/lifecycle/SeamPortletLifecycle.java)
===================================================================
--- branches/3.1.x/extensions/portletbridge/portletbridge-impl/src/main/java/org/ajax4jsf/portlet/lifecycle/SeamPortletLifecycle.java	                        (rev 0)
+++ branches/3.1.x/extensions/portletbridge/portletbridge-impl/src/main/java/org/ajax4jsf/portlet/lifecycle/SeamPortletLifecycle.java	2008-01-26 01:04:53 UTC (rev 5657)
@@ -0,0 +1,66 @@
+/**
+ * 
+ */
+package org.ajax4jsf.portlet.lifecycle;
+
+import javax.faces.FacesException;
+import javax.faces.context.FacesContext;
+import javax.faces.event.PhaseListener;
+import javax.faces.lifecycle.Lifecycle;
+
+import org.jboss.seam.jsf.SeamPhaseListenerWrapper;
+
+/**
+ * @author asmirnov
+ *
+ */
+public class SeamPortletLifecycle extends PortletLifecycle {
+	
+	public static final String SEAM_PORTLET_LIFECYCLE = "SEAM_PORTLET";
+	public static final String SEAM_PHASE_LISTENER_CLASS = "org.jboss.seam.jsf.SeamPhaseListener";
+
+	
+	private PhaseListener seamListener;
+	
+	private SeamPhaseListenerWrapper seamListenerWrapper;
+
+
+    /**
+     * @param listener
+     * @see javax.faces.lifecycle.Lifecycle#addPhaseListener(javax.faces.event.PhaseListener)
+     */
+    public void addPhaseListener(PhaseListener listener) {
+			// Existing Seam 2.0 releases hack - replace SeamPhaseListener by our bridge-compatible version.
+			if(SEAM_PHASE_LISTENER_CLASS.equals(listener.getClass().getName())){
+				if(null == seamListener){
+					seamListener = listener;
+					seamListenerWrapper = new SeamPhaseListenerWrapper(listener);
+					addPhaseListener(0, seamListenerWrapper);
+				} else {
+					throw new FacesException("Attempt to register second SeamPhaseListener");
+				}
+			} else {
+				super.addPhaseListener(listener);
+			}
+    }
+
+
+
+
+
+	/**
+	 * @param listener
+	 * @see javax.faces.lifecycle.Lifecycle#removePhaseListener(javax.faces.event.PhaseListener)
+	 */
+	public void removePhaseListener(PhaseListener listener) {
+		if(listener == this.seamListener){
+			listener = seamListenerWrapper;
+			seamListener = seamListenerWrapper = null;
+		}
+		super.removePhaseListener(listener);
+	}
+
+
+
+    
+}

Copied: branches/3.1.x/extensions/portletbridge/portletbridge-impl/src/main/java/org/ajax4jsf/portlet/seam/ConversationIdRetriver.java (from rev 5656, trunk/extensions/portletbridge/portletbridge-impl/src/main/java/org/ajax4jsf/portlet/seam/ConversationIdRetriver.java)
===================================================================
--- branches/3.1.x/extensions/portletbridge/portletbridge-impl/src/main/java/org/ajax4jsf/portlet/seam/ConversationIdRetriver.java	                        (rev 0)
+++ branches/3.1.x/extensions/portletbridge/portletbridge-impl/src/main/java/org/ajax4jsf/portlet/seam/ConversationIdRetriver.java	2008-01-26 01:04:53 UTC (rev 5657)
@@ -0,0 +1,36 @@
+/**
+ * 
+ */
+package org.ajax4jsf.portlet.seam;
+
+import java.util.Map;
+
+import org.ajax4jsf.portlet.application.PortletViewState;
+import org.jboss.seam.contexts.Contexts;
+import org.jboss.seam.core.Manager;
+
+/**
+ * @author asmirnov
+ * 
+ */
+public class ConversationIdRetriver {
+
+	public ConversationIdRetriver() {
+		// Attempt to load Manager class.
+		Manager.class.getName();
+	}
+
+	public void setConversationIdParameter(PortletViewState state) {
+		if (Contexts.isEventContextActive()) {
+			Manager manager = Manager.instance();
+			if (manager.isLongRunningConversation()) {
+				state.setConversationIdParameter(manager.getConversationIdParameter());
+				state.setConversationId( manager.getCurrentConversationId() );
+			} else {
+				state.setConversationIdParameter(null);
+				state.setConversationId(null);
+			}
+		}
+	}
+
+}

Modified: branches/3.1.x/extensions/portletbridge/portletbridge-impl/src/main/java/org/ajax4jsf/portlet/seam/SeamPhaseListener.java
===================================================================
--- branches/3.1.x/extensions/portletbridge/portletbridge-impl/src/main/java/org/ajax4jsf/portlet/seam/SeamPhaseListener.java	2008-01-26 00:38:11 UTC (rev 5656)
+++ branches/3.1.x/extensions/portletbridge/portletbridge-impl/src/main/java/org/ajax4jsf/portlet/seam/SeamPhaseListener.java	2008-01-26 01:04:53 UTC (rev 5657)
@@ -57,7 +57,7 @@
  */
 public class SeamPhaseListener implements PhaseListener
 {
-   private static final long serialVersionUID = -9127555729455066493L;
+   private static final long serialVersionUID = -91275557294550234L;
    
    private static final LogProvider log = Logging.getLogProvider(SeamPhaseListener.class);
    

Copied: branches/3.1.x/extensions/portletbridge/portletbridge-impl/src/main/java/org/jboss (from rev 5656, trunk/extensions/portletbridge/portletbridge-impl/src/main/java/org/jboss)

Copied: branches/3.1.x/extensions/portletbridge/portletbridge-impl/src/main/java/org/jboss/seam (from rev 5656, trunk/extensions/portletbridge/portletbridge-impl/src/main/java/org/jboss/seam)

Copied: branches/3.1.x/extensions/portletbridge/portletbridge-impl/src/main/java/org/jboss/seam/jsf (from rev 5656, trunk/extensions/portletbridge/portletbridge-impl/src/main/java/org/jboss/seam/jsf)

Deleted: branches/3.1.x/extensions/portletbridge/portletbridge-impl/src/main/java/org/jboss/seam/jsf/SeamPhaseListenerWrapper.java
===================================================================
--- trunk/extensions/portletbridge/portletbridge-impl/src/main/java/org/jboss/seam/jsf/SeamPhaseListenerWrapper.java	2008-01-26 00:38:11 UTC (rev 5656)
+++ branches/3.1.x/extensions/portletbridge/portletbridge-impl/src/main/java/org/jboss/seam/jsf/SeamPhaseListenerWrapper.java	2008-01-26 01:04:53 UTC (rev 5657)
@@ -1,188 +0,0 @@
-/**
- * 
- */
-package org.jboss.seam.jsf;
-
-import static javax.faces.event.PhaseId.INVOKE_APPLICATION;
-import static javax.faces.event.PhaseId.PROCESS_VALIDATIONS;
-import static javax.faces.event.PhaseId.RENDER_RESPONSE;
-import static javax.faces.event.PhaseId.RESTORE_VIEW;
-
-import javax.faces.context.ExternalContext;
-import javax.faces.context.FacesContext;
-import javax.faces.event.PhaseEvent;
-import javax.faces.event.PhaseId;
-import javax.faces.event.PhaseListener;
-import javax.portlet.faces.Bridge;
-import javax.portlet.faces.Bridge.PortletPhase;
-
-import org.ajax4jsf.portlet.application.PortletStateHolder;
-import org.ajax4jsf.portlet.application.PortletViewState;
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
-import org.jboss.seam.contexts.Contexts;
-import org.jboss.seam.contexts.FacesLifecycle;
-import org.jboss.seam.core.Manager;
-import org.jboss.seam.exception.Exceptions;
-import org.jboss.seam.faces.FacesMessages;
-
-/**
- * @author asmirnov
- * 
- */
-public class SeamPhaseListenerWrapper implements PhaseListener {
-
-	private final SeamPhaseListener _defaultListener;
-
-	private static final Log log = LogFactory
-			.getLog(SeamPhaseListenerWrapper.class);
-
-	/**
-	 * @param defaultListener
-	 */
-	public SeamPhaseListenerWrapper(PhaseListener defaultListener) {
-		_defaultListener = (SeamPhaseListener) defaultListener;
-	}
-
-	/**
-	 * 
-	 */
-	private static final long serialVersionUID = -8465467659533393697L;
-
-	/*
-	 * (non-Javadoc)
-	 * 
-	 * @see javax.faces.event.PhaseListener#afterPhase(javax.faces.event.PhaseEvent)
-	 */
-	public void afterPhase(PhaseEvent event) {
-		FacesContext facesContext = event.getFacesContext();
-		ExternalContext externalContext = facesContext.getExternalContext();
-		Bridge.PortletPhase portletPhase = (PortletPhase) externalContext
-				.getRequestMap().get(Bridge.PORTLET_LIFECYCLE_PHASE);
-		if (null != portletPhase) {
-			try {
-				_defaultListener.raiseEventsAfterPhase(event);
-				afterPortletPhase(event, facesContext, portletPhase);
-			} catch (Exception e) {
-				log.debug("uncaught exception, try to recovery", e);
-				try {
-					Exceptions.instance().handle(e);
-					// A redirect occurred inside the error handler, and we are
-					// in after
-					// phase, so we need to clean up now as there are no more
-					// after
-					// phases to be run
-					if (facesContext.getResponseComplete()) {
-						_defaultListener.afterResponseComplete(facesContext);
-					}
-				} catch (Exception ehe) {
-					log.error("swallowing exception", e);
-				}
-			}
-			FacesLifecycle.clearPhaseId();
-
-		} else {
-			_defaultListener.afterPhase(event);
-		}
-	}
-
-	private void afterPortletPhase(PhaseEvent event, FacesContext facesContext,
-			PortletPhase portletPhase) {
-
-		PhaseId phaseId = event.getPhaseId();
-		if (phaseId == RESTORE_VIEW) {
-			_defaultListener.afterRestoreView(facesContext);
-		} else if (phaseId == INVOKE_APPLICATION) {
-			_defaultListener.afterInvokeApplication();
-		} else if (phaseId == PROCESS_VALIDATIONS) {
-			_defaultListener.afterProcessValidations(facesContext);
-		}
-
-		FacesMessages.afterPhase();
-
-		// delegate to subclass:
-		_defaultListener.handleTransactionsAfterPhase(event);
-
-		if (phaseId == RENDER_RESPONSE) {
-			// writeConversationIdToResponse(
-			// facesContext.getExternalContext().getResponse() );
-			_defaultListener.afterRenderResponse(facesContext);
-		} else if (Bridge.PortletPhase.ActionPhase.equals(portletPhase)
-				&& (phaseId == INVOKE_APPLICATION
-						|| facesContext.getRenderResponse() || facesContext
-						.getResponseComplete())) {
-			Manager manager = Manager.instance();
-			manager.beforeRedirect();
-			// save Seam conversation Id.
-			PortletViewState windowState = PortletStateHolder.getInstance(
-					facesContext).getWindowState(facesContext);	
-			windowState.saveSeamConversationId(facesContext);
-			_defaultListener.afterResponseComplete(facesContext);
-		}
-
-	}
-
-	/*
-	 * (non-Javadoc)
-	 * 
-	 * @see javax.faces.event.PhaseListener#beforePhase(javax.faces.event.PhaseEvent)
-	 */
-	public void beforePhase(PhaseEvent event) {
-		FacesContext facesContext = event.getFacesContext();
-		ExternalContext externalContext = facesContext.getExternalContext();
-		Bridge.PortletPhase portletPhase = (PortletPhase) externalContext
-				.getRequestMap().get(Bridge.PORTLET_LIFECYCLE_PHASE);
-		if (null != portletPhase) {
-			log.trace("before phase: " + event.getPhaseId());
-
-			FacesLifecycle.setPhaseId(event.getPhaseId());
-
-			try {
-				beforePortletPhase(event, facesContext, portletPhase);
-				_defaultListener.raiseEventsBeforePhase(event);
-			} catch (Exception e) {
-				log.debug("uncaught exception, try to recovery", e);
-				try {
-					Exceptions.instance().handle(e);
-				} catch (Exception ehe) {
-					log.error("swallowing exception", e);
-				}
-			}
-		} else {
-			_defaultListener.beforePhase(event);
-		}
-	}
-
-	private void beforePortletPhase(PhaseEvent event,
-			FacesContext facesContext, PortletPhase portletPhase) {
-
-		boolean notInitialised=false;
-		if (event.getPhaseId() == RESTORE_VIEW ) {
-			_defaultListener.beforeRestoreView(facesContext);
-		}
-
-		if (event.getPhaseId() == RENDER_RESPONSE && !Contexts.isApplicationContextActive()) {
-			_defaultListener.beforeRestoreView(facesContext);
-			notInitialised = true;
-		}
-		// delegate to subclass:
-		_defaultListener.handleTransactionsBeforePhase(event);
-
-		if (event.getPhaseId() == RENDER_RESPONSE) {
-			if(notInitialised){
-				_defaultListener.afterRestoreView(facesContext);
-			}
-			_defaultListener.beforeRenderResponse(facesContext);
-		}
-	}
-
-	/*
-	 * (non-Javadoc)
-	 * 
-	 * @see javax.faces.event.PhaseListener#getPhaseId()
-	 */
-	public PhaseId getPhaseId() {
-		return _defaultListener.getPhaseId();
-	}
-
-}

Copied: branches/3.1.x/extensions/portletbridge/portletbridge-impl/src/main/java/org/jboss/seam/jsf/SeamPhaseListenerWrapper.java (from rev 5656, trunk/extensions/portletbridge/portletbridge-impl/src/main/java/org/jboss/seam/jsf/SeamPhaseListenerWrapper.java)
===================================================================
--- branches/3.1.x/extensions/portletbridge/portletbridge-impl/src/main/java/org/jboss/seam/jsf/SeamPhaseListenerWrapper.java	                        (rev 0)
+++ branches/3.1.x/extensions/portletbridge/portletbridge-impl/src/main/java/org/jboss/seam/jsf/SeamPhaseListenerWrapper.java	2008-01-26 01:04:53 UTC (rev 5657)
@@ -0,0 +1,188 @@
+/**
+ * 
+ */
+package org.jboss.seam.jsf;
+
+import static javax.faces.event.PhaseId.INVOKE_APPLICATION;
+import static javax.faces.event.PhaseId.PROCESS_VALIDATIONS;
+import static javax.faces.event.PhaseId.RENDER_RESPONSE;
+import static javax.faces.event.PhaseId.RESTORE_VIEW;
+
+import javax.faces.context.ExternalContext;
+import javax.faces.context.FacesContext;
+import javax.faces.event.PhaseEvent;
+import javax.faces.event.PhaseId;
+import javax.faces.event.PhaseListener;
+import javax.portlet.faces.Bridge;
+import javax.portlet.faces.Bridge.PortletPhase;
+
+import org.ajax4jsf.portlet.application.PortletStateHolder;
+import org.ajax4jsf.portlet.application.PortletViewState;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.jboss.seam.contexts.Contexts;
+import org.jboss.seam.contexts.FacesLifecycle;
+import org.jboss.seam.core.Manager;
+import org.jboss.seam.exception.Exceptions;
+import org.jboss.seam.faces.FacesMessages;
+
+/**
+ * @author asmirnov
+ * 
+ */
+public class SeamPhaseListenerWrapper implements PhaseListener {
+
+	private final SeamPhaseListener _defaultListener;
+
+	private static final Log log = LogFactory
+			.getLog(SeamPhaseListenerWrapper.class);
+
+	/**
+	 * @param defaultListener
+	 */
+	public SeamPhaseListenerWrapper(PhaseListener defaultListener) {
+		_defaultListener = (SeamPhaseListener) defaultListener;
+	}
+
+	/**
+	 * 
+	 */
+	private static final long serialVersionUID = -8465467659533393697L;
+
+	/*
+	 * (non-Javadoc)
+	 * 
+	 * @see javax.faces.event.PhaseListener#afterPhase(javax.faces.event.PhaseEvent)
+	 */
+	public void afterPhase(PhaseEvent event) {
+		FacesContext facesContext = event.getFacesContext();
+		ExternalContext externalContext = facesContext.getExternalContext();
+		Bridge.PortletPhase portletPhase = (PortletPhase) externalContext
+				.getRequestMap().get(Bridge.PORTLET_LIFECYCLE_PHASE);
+		if (null != portletPhase) {
+			try {
+				_defaultListener.raiseEventsAfterPhase(event);
+				afterPortletPhase(event, facesContext, portletPhase);
+			} catch (Exception e) {
+				log.debug("uncaught exception, try to recovery", e);
+				try {
+					Exceptions.instance().handle(e);
+					// A redirect occurred inside the error handler, and we are
+					// in after
+					// phase, so we need to clean up now as there are no more
+					// after
+					// phases to be run
+					if (facesContext.getResponseComplete()) {
+						_defaultListener.afterResponseComplete(facesContext);
+					}
+				} catch (Exception ehe) {
+					log.error("swallowing exception", e);
+				}
+			}
+			FacesLifecycle.clearPhaseId();
+
+		} else {
+			_defaultListener.afterPhase(event);
+		}
+	}
+
+	private void afterPortletPhase(PhaseEvent event, FacesContext facesContext,
+			PortletPhase portletPhase) {
+
+		PhaseId phaseId = event.getPhaseId();
+		if (phaseId == RESTORE_VIEW) {
+			_defaultListener.afterRestoreView(facesContext);
+		} else if (phaseId == INVOKE_APPLICATION) {
+			_defaultListener.afterInvokeApplication();
+		} else if (phaseId == PROCESS_VALIDATIONS) {
+			_defaultListener.afterProcessValidations(facesContext);
+		}
+
+		FacesMessages.afterPhase();
+
+		// delegate to subclass:
+		_defaultListener.handleTransactionsAfterPhase(event);
+
+		if (phaseId == RENDER_RESPONSE) {
+			// writeConversationIdToResponse(
+			// facesContext.getExternalContext().getResponse() );
+			_defaultListener.afterRenderResponse(facesContext);
+		} else if (Bridge.PortletPhase.ActionPhase.equals(portletPhase)
+				&& (phaseId == INVOKE_APPLICATION
+						|| facesContext.getRenderResponse() || facesContext
+						.getResponseComplete())) {
+			Manager manager = Manager.instance();
+			manager.beforeRedirect();
+			// save Seam conversation Id.
+			PortletViewState windowState = PortletStateHolder.getInstance(
+					facesContext).getWindowState(facesContext);	
+			windowState.saveSeamConversationId(facesContext);
+			_defaultListener.afterResponseComplete(facesContext);
+		}
+
+	}
+
+	/*
+	 * (non-Javadoc)
+	 * 
+	 * @see javax.faces.event.PhaseListener#beforePhase(javax.faces.event.PhaseEvent)
+	 */
+	public void beforePhase(PhaseEvent event) {
+		FacesContext facesContext = event.getFacesContext();
+		ExternalContext externalContext = facesContext.getExternalContext();
+		Bridge.PortletPhase portletPhase = (PortletPhase) externalContext
+				.getRequestMap().get(Bridge.PORTLET_LIFECYCLE_PHASE);
+		if (null != portletPhase) {
+			log.trace("before phase: " + event.getPhaseId());
+
+			FacesLifecycle.setPhaseId(event.getPhaseId());
+
+			try {
+				beforePortletPhase(event, facesContext, portletPhase);
+				_defaultListener.raiseEventsBeforePhase(event);
+			} catch (Exception e) {
+				log.debug("uncaught exception, try to recovery", e);
+				try {
+					Exceptions.instance().handle(e);
+				} catch (Exception ehe) {
+					log.error("swallowing exception", e);
+				}
+			}
+		} else {
+			_defaultListener.beforePhase(event);
+		}
+	}
+
+	private void beforePortletPhase(PhaseEvent event,
+			FacesContext facesContext, PortletPhase portletPhase) {
+
+		boolean notInitialised=false;
+		if (event.getPhaseId() == RESTORE_VIEW ) {
+			_defaultListener.beforeRestoreView(facesContext);
+		}
+
+		if (event.getPhaseId() == RENDER_RESPONSE && !Contexts.isApplicationContextActive()) {
+			_defaultListener.beforeRestoreView(facesContext);
+			notInitialised = true;
+		}
+		// delegate to subclass:
+		_defaultListener.handleTransactionsBeforePhase(event);
+
+		if (event.getPhaseId() == RENDER_RESPONSE) {
+			if(notInitialised){
+				_defaultListener.afterRestoreView(facesContext);
+			}
+			_defaultListener.beforeRenderResponse(facesContext);
+		}
+	}
+
+	/*
+	 * (non-Javadoc)
+	 * 
+	 * @see javax.faces.event.PhaseListener#getPhaseId()
+	 */
+	public PhaseId getPhaseId() {
+		return _defaultListener.getPhaseId();
+	}
+
+}

Copied: branches/3.1.x/extensions/portletbridge/portletbridge-impl/src/main/resources/META-INF/.faces-config.xml.jsfdia (from rev 5656, trunk/extensions/portletbridge/portletbridge-impl/src/main/resources/META-INF/.faces-config.xml.jsfdia)
===================================================================
--- branches/3.1.x/extensions/portletbridge/portletbridge-impl/src/main/resources/META-INF/.faces-config.xml.jsfdia	                        (rev 0)
+++ branches/3.1.x/extensions/portletbridge/portletbridge-impl/src/main/resources/META-INF/.faces-config.xml.jsfdia	2008-01-26 01:04:53 UTC (rev 5657)
@@ -0,0 +1,2 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<PROCESS ENTITY="JSFProcess"/>

Modified: branches/3.1.x/extensions/portletbridge/portletbridge-impl/src/main/resources/META-INF/faces-config.xml
===================================================================
--- branches/3.1.x/extensions/portletbridge/portletbridge-impl/src/main/resources/META-INF/faces-config.xml	2008-01-26 00:38:11 UTC (rev 5656)
+++ branches/3.1.x/extensions/portletbridge/portletbridge-impl/src/main/resources/META-INF/faces-config.xml	2008-01-26 01:04:53 UTC (rev 5657)
@@ -10,6 +10,9 @@
 		<faces-context-factory>
 			org.ajax4jsf.portlet.context.FacesContextFactoryImpl
 		</faces-context-factory>
+		<lifecycle-factory>
+			org.ajax4jsf.portlet.lifecycle.PortletLifecycleFactory
+		</lifecycle-factory>
 	</factory>
 	<lifecycle>
 		<phase-listener>

Modified: branches/3.1.x/extensions/portletbridge/portletbridge-impl/src/test/java/org/ajax4jsf/portlet/context/PortletExternalContextTest.java
===================================================================
--- branches/3.1.x/extensions/portletbridge/portletbridge-impl/src/test/java/org/ajax4jsf/portlet/context/PortletExternalContextTest.java	2008-01-26 00:38:11 UTC (rev 5656)
+++ branches/3.1.x/extensions/portletbridge/portletbridge-impl/src/test/java/org/ajax4jsf/portlet/context/PortletExternalContextTest.java	2008-01-26 01:04:53 UTC (rev 5657)
@@ -70,7 +70,7 @@
      */
     public final void testGetInitParameterString() {
 	assertNull(portalFacesContext.getExternalContext().getInitParameter("blabla"));
-//	assertSame(MockPortletContext.PORTLET_INIT_VALUE, portalFacesContext.getExternalContext().getInitParameter(MockPortletContext.INIT_PARAMETER));
+	assertSame(MockPortletContext.PORTLET_INIT_VALUE, portalFacesContext.getExternalContext().getInitParameter(MockPortletContext.INIT_PARAMETER));
     }
 
     /**

Modified: branches/3.1.x/framework/impl/src/main/java/org/ajax4jsf/application/AjaxStateManager.java
===================================================================
--- branches/3.1.x/framework/impl/src/main/java/org/ajax4jsf/application/AjaxStateManager.java	2008-01-26 00:38:11 UTC (rev 5656)
+++ branches/3.1.x/framework/impl/src/main/java/org/ajax4jsf/application/AjaxStateManager.java	2008-01-26 01:04:53 UTC (rev 5657)
@@ -325,7 +325,7 @@
 	protected SerializedView buildSerializedView(FacesContext context) {
 		SerializedView serializedView = null;
 		UIViewRoot viewRoot = context.getViewRoot();
-		if (!viewRoot.isTransient()) {
+		if (null != viewRoot && (!viewRoot.isTransient()) ) {
 			TreeStrutureNode treeStructure = new TreeStrutureNode();
 			treeStructure.apply(context, viewRoot, new HashSet());
 			Object treeState = viewRoot.processSaveState(context);

Modified: branches/3.1.x/framework/impl/src/main/java/org/ajax4jsf/context/AjaxContextImpl.java
===================================================================
--- branches/3.1.x/framework/impl/src/main/java/org/ajax4jsf/context/AjaxContextImpl.java	2008-01-26 00:38:11 UTC (rev 5656)
+++ branches/3.1.x/framework/impl/src/main/java/org/ajax4jsf/context/AjaxContextImpl.java	2008-01-26 01:04:53 UTC (rev 5657)
@@ -443,7 +443,7 @@
 		StateManager stateManager = context.getApplication().getStateManager();
 		SerializedView serializedView = stateManager
 				.saveSerializedView(context);
-		if (null != serializedView) {
+		if (null != writer && null != serializedView) {
 			StringWriter bufWriter = new StringWriter();
 			ResponseWriter cloneWithWriter = writer.cloneWithWriter(bufWriter);
 			context.setResponseWriter(cloneWithWriter);




More information about the richfaces-svn-commits mailing list