Author: alexsmirnov
Date: 2008-01-15 20:35:34 -0500 (Tue, 15 Jan 2008)
New Revision: 5404
Added:
trunk/extensions/portletbridge/portletbridge-api/src/test/java/org/ajax4jsf/portlet/MockPortletSession.java
trunk/extensions/portletbridge/portletbridge-impl/src/main/java/org/ajax4jsf/portlet/seam/
trunk/extensions/portletbridge/portletbridge-impl/src/main/java/org/ajax4jsf/portlet/seam/SeamPhaseListener.java
trunk/extensions/portletbridge/portletbridge-impl/src/test/java/org/ajax4jsf/portlet/seam/
trunk/extensions/portletbridge/portletbridge-impl/src/test/java/org/ajax4jsf/portlet/seam/AbstractSeamPortletTestCase.java
trunk/extensions/portletbridge/portletbridge-impl/src/test/java/org/ajax4jsf/portlet/seam/MockUserTransaction.java
trunk/extensions/portletbridge/portletbridge-impl/src/test/java/org/ajax4jsf/portlet/seam/PhaseListenerActionPhaseTest.java
trunk/samples/seamPortletEar/seamBookingPortlet/src/main/java/org/ajax4jsf/portlet/seam/SeamPhaseListener.java
Modified:
trunk/extensions/portletbridge/portletbridge-api/src/test/java/org/ajax4jsf/portlet/AbstractAjax4jsfPortletTestCase.java
trunk/extensions/portletbridge/portletbridge-api/src/test/java/org/ajax4jsf/portlet/MockActionRequest.java
trunk/extensions/portletbridge/portletbridge-api/src/test/java/org/ajax4jsf/portlet/MockPortletContext.java
trunk/extensions/portletbridge/portletbridge-api/src/test/java/org/ajax4jsf/portlet/MockPortletRequest.java
trunk/extensions/portletbridge/portletbridge-api/src/test/java/org/ajax4jsf/portlet/MockRenderRequest.java
trunk/extensions/portletbridge/portletbridge-impl/pom.xml
trunk/extensions/portletbridge/portletbridge-impl/src/test/java/org/ajax4jsf/portlet/context/ContextFactoryTest.java
trunk/extensions/portletbridge/portletbridge-impl/src/test/java/org/ajax4jsf/portlet/context/PortletExternalContextTest.java
trunk/samples/scrollableDataTableDemo/src/main/webapp/WEB-INF/web.xml
Log:
Create Seam test classes for a portlet requests.
Modified:
trunk/extensions/portletbridge/portletbridge-api/src/test/java/org/ajax4jsf/portlet/AbstractAjax4jsfPortletTestCase.java
===================================================================
---
trunk/extensions/portletbridge/portletbridge-api/src/test/java/org/ajax4jsf/portlet/AbstractAjax4jsfPortletTestCase.java 2008-01-16
01:30:07 UTC (rev 5403)
+++
trunk/extensions/portletbridge/portletbridge-api/src/test/java/org/ajax4jsf/portlet/AbstractAjax4jsfPortletTestCase.java 2008-01-16
01:35:34 UTC (rev 5404)
@@ -24,7 +24,7 @@
public void setUp() throws Exception {
super.setUp();
- portletContext = new MockPortletContext();
+ portletContext = new MockPortletContext(servletContext);
portletConfig = new MockPortletConfig(portletContext);
}
@@ -42,7 +42,7 @@
*
*/
protected void setupActionRequest() {
- actionRequest = new MockActionRequest();
+ actionRequest = new MockActionRequest(portletContext);
actionResponse = new MockActionResponse();
externalContext.setRequest(actionRequest);
externalContext.setResponse(actionResponse);
@@ -52,7 +52,7 @@
*
*/
protected void setupRenderRequest() {
- renderRequest = new MockRenderRequest();
+ renderRequest = new MockRenderRequest(portletContext);
renderResponse = new MockRenderResponse();
externalContext.setRequest(renderRequest);
externalContext.setResponse(renderResponse);
Modified:
trunk/extensions/portletbridge/portletbridge-api/src/test/java/org/ajax4jsf/portlet/MockActionRequest.java
===================================================================
---
trunk/extensions/portletbridge/portletbridge-api/src/test/java/org/ajax4jsf/portlet/MockActionRequest.java 2008-01-16
01:30:07 UTC (rev 5403)
+++
trunk/extensions/portletbridge/portletbridge-api/src/test/java/org/ajax4jsf/portlet/MockActionRequest.java 2008-01-16
01:35:34 UTC (rev 5404)
@@ -8,6 +8,7 @@
import java.io.InputStream;
import java.io.UnsupportedEncodingException;
import javax.portlet.ActionRequest;
+import javax.portlet.PortletContext;
/**
* @author asmirnov
@@ -15,7 +16,12 @@
*/
public class MockActionRequest extends MockPortletRequest implements
ActionRequest {
- /* (non-Javadoc)
+ public MockActionRequest(PortletContext portletContext) {
+ super(portletContext);
+ // TODO Auto-generated constructor stub
+ }
+
+ /* (non-Javadoc)
* @see javax.portlet.ActionRequest#getCharacterEncoding()
*/
public String getCharacterEncoding() {
Modified:
trunk/extensions/portletbridge/portletbridge-api/src/test/java/org/ajax4jsf/portlet/MockPortletContext.java
===================================================================
---
trunk/extensions/portletbridge/portletbridge-api/src/test/java/org/ajax4jsf/portlet/MockPortletContext.java 2008-01-16
01:30:07 UTC (rev 5403)
+++
trunk/extensions/portletbridge/portletbridge-api/src/test/java/org/ajax4jsf/portlet/MockPortletContext.java 2008-01-16
01:35:34 UTC (rev 5404)
@@ -14,6 +14,8 @@
import javax.portlet.PortletContext;
import javax.portlet.PortletRequestDispatcher;
+import org.apache.shale.test.mock.MockServletContext;
+
/**
* @author asmirnov
*
@@ -22,42 +24,39 @@
public static final String PORTLET_INIT_VALUE = "portlet_init_value";
public static final String INIT_PARAMETER = "init_parameter";
- private Map<String, String> initParameters;
- private Map<String, Object> attributes;
+ private MockServletContext servletContext;
- public MockPortletContext() {
- initParameters = new HashMap<String, String>();
- initParameters.put(INIT_PARAMETER, PORTLET_INIT_VALUE);
- attributes = new HashMap<String, Object>();
+ public MockPortletContext(MockServletContext sc) {
+ servletContext = sc;
}
/* (non-Javadoc)
* @see javax.portlet.PortletContext#getAttribute(java.lang.String)
*/
public Object getAttribute(String arg0) {
- return attributes.get(arg0);
+ return servletContext.getAttribute(arg0);
}
/* (non-Javadoc)
* @see javax.portlet.PortletContext#getAttributeNames()
*/
public Enumeration getAttributeNames() {
- return Collections.enumeration(attributes.keySet());
+ return servletContext.getAttributeNames();
}
/* (non-Javadoc)
* @see javax.portlet.PortletContext#getInitParameter(java.lang.String)
*/
public String getInitParameter(String arg0) {
- return initParameters.get(arg0);
+ return servletContext.getInitParameter(arg0);
}
/* (non-Javadoc)
* @see javax.portlet.PortletContext#getInitParameterNames()
*/
public Enumeration getInitParameterNames() {
- return Collections.enumeration(initParameters.keySet());
+ return servletContext.getInitParameterNames();
}
/* (non-Javadoc)
@@ -72,8 +71,8 @@
* @see javax.portlet.PortletContext#getMimeType(java.lang.String)
*/
public String getMimeType(String arg0) {
- // TODO Auto-generated method stub
- return null;
+ // TODO Auto-generated method stub
+ return servletContext.getMimeType(arg0);
}
/* (non-Javadoc)
@@ -97,7 +96,7 @@
*/
public String getPortletContextName() {
// TODO Auto-generated method stub
- return null;
+ return "testPortlet";
}
/* (non-Javadoc)
@@ -105,7 +104,7 @@
*/
public String getRealPath(String arg0) {
// TODO Auto-generated method stub
- return null;
+ return servletContext.getRealPath(arg0);
}
/* (non-Javadoc)
@@ -121,7 +120,7 @@
*/
public URL getResource(String arg0) throws MalformedURLException {
// TODO Auto-generated method stub
- return null;
+ return servletContext.getResource(arg0);
}
/* (non-Javadoc)
@@ -129,7 +128,7 @@
*/
public InputStream getResourceAsStream(String arg0) {
// TODO Auto-generated method stub
- return null;
+ return servletContext.getResourceAsStream(arg0);
}
/* (non-Javadoc)
@@ -137,7 +136,7 @@
*/
public Set getResourcePaths(String arg0) {
// TODO Auto-generated method stub
- return null;
+ return servletContext.getResourcePaths(arg0);
}
/* (non-Javadoc)
@@ -145,7 +144,7 @@
*/
public String getServerInfo() {
// TODO Auto-generated method stub
- return null;
+ return servletContext.getServerInfo();
}
/* (non-Javadoc)
@@ -153,6 +152,7 @@
*/
public void log(String arg0) {
// TODO Auto-generated method stub
+ servletContext.log(arg0);
}
/* (non-Javadoc)
@@ -160,23 +160,24 @@
*/
public void log(String arg0, Throwable arg1) {
// TODO Auto-generated method stub
+ servletContext.log(arg0, arg1);
}
/* (non-Javadoc)
* @see javax.portlet.PortletContext#removeAttribute(java.lang.String)
*/
public void removeAttribute(String arg0) {
- attributes.remove(arg0);
+ servletContext.removeAttribute(arg0);
}
/* (non-Javadoc)
* @see javax.portlet.PortletContext#setAttribute(java.lang.String,
java.lang.Object)
*/
public void setAttribute(String arg0, Object arg1) {
- attributes.put(arg0, arg1);
+ servletContext.setAttribute(arg0, arg1);
}
public void setInitParameter(String name, String value) {
- initParameters.put(name, value);
+ servletContext.addInitParameter(name, value);
}
}
Modified:
trunk/extensions/portletbridge/portletbridge-api/src/test/java/org/ajax4jsf/portlet/MockPortletRequest.java
===================================================================
---
trunk/extensions/portletbridge/portletbridge-api/src/test/java/org/ajax4jsf/portlet/MockPortletRequest.java 2008-01-16
01:30:07 UTC (rev 5403)
+++
trunk/extensions/portletbridge/portletbridge-api/src/test/java/org/ajax4jsf/portlet/MockPortletRequest.java 2008-01-16
01:35:34 UTC (rev 5404)
@@ -11,6 +11,7 @@
import java.util.Locale;
import java.util.Map;
import javax.portlet.PortalContext;
+import javax.portlet.PortletContext;
import javax.portlet.PortletMode;
import javax.portlet.PortletPreferences;
import javax.portlet.PortletRequest;
@@ -32,8 +33,10 @@
public Map attributes = new HashMap();
public PortletMode mode = PortletMode.VIEW;
public WindowState windowState = WindowState.NORMAL;
+ public MockPortletSession portletSession = null;
+ private PortletContext portletContext;
- public MockPortletRequest() {
+ public MockPortletRequest(PortletContext portletContext) {
parameters.put(PARAMETER, new String[]{PARAMETER_VALUE1,PARAMETER_VALUE2});
}
/* (non-Javadoc)
@@ -139,15 +142,17 @@
*/
public PortletSession getPortletSession() {
// TODO Auto-generated method stub
- return null;
+ return getPortletSession(true);
}
/* (non-Javadoc)
* @see javax.portlet.PortletRequest#getPortletSession(boolean)
*/
public PortletSession getPortletSession(boolean arg0) {
- // TODO Auto-generated method stub
- return null;
+ if(arg0 && null == portletSession){
+ portletSession = new MockPortletSession(portletContext);
+ }
+ return portletSession;
}
/* (non-Javadoc)
Added:
trunk/extensions/portletbridge/portletbridge-api/src/test/java/org/ajax4jsf/portlet/MockPortletSession.java
===================================================================
---
trunk/extensions/portletbridge/portletbridge-api/src/test/java/org/ajax4jsf/portlet/MockPortletSession.java
(rev 0)
+++
trunk/extensions/portletbridge/portletbridge-api/src/test/java/org/ajax4jsf/portlet/MockPortletSession.java 2008-01-16
01:35:34 UTC (rev 5404)
@@ -0,0 +1,168 @@
+/**
+ *
+ */
+package org.ajax4jsf.portlet;
+
+import java.util.Collections;
+import java.util.Enumeration;
+import java.util.HashMap;
+import java.util.Map;
+
+import javax.portlet.PortletContext;
+import javax.portlet.PortletSession;
+
+/**
+ * @author asmirnov
+ *
+ */
+public class MockPortletSession implements PortletSession {
+
+ private static final String ID = "foobar";
+
+ private Map<String, Object> portletScopeAttributes;
+
+ private Map<String, Object> appScopeAttributes;
+
+ private long created;
+
+ private PortletContext portletContext;
+
+ private int maxInactive = 0;
+
+ public MockPortletSession(PortletContext pc) {
+ portletContext = pc;
+ portletScopeAttributes = new HashMap<String, Object>();
+ appScopeAttributes = new HashMap<String, Object>();
+ created = System.currentTimeMillis();
+ }
+
+ private Map<String,Object> getAttributesMap(int scope) {
+ return scope == PORTLET_SCOPE?portletScopeAttributes:appScopeAttributes;
+ }
+ /* (non-Javadoc)
+ * @see javax.portlet.PortletSession#getAttribute(java.lang.String)
+ */
+ public Object getAttribute(String arg0) {
+ // TODO Auto-generated method stub
+ return getAttribute(arg0, PORTLET_SCOPE);
+ }
+
+ /* (non-Javadoc)
+ * @see javax.portlet.PortletSession#getAttribute(java.lang.String, int)
+ */
+ public Object getAttribute(String arg0, int arg1) {
+ return getAttributesMap(arg1).get(arg0);
+ }
+
+ /* (non-Javadoc)
+ * @see javax.portlet.PortletSession#getAttributeNames()
+ */
+ public Enumeration getAttributeNames() {
+ // TODO Auto-generated method stub
+ return getAttributeNames(PORTLET_SCOPE);
+ }
+
+ /* (non-Javadoc)
+ * @see javax.portlet.PortletSession#getAttributeNames(int)
+ */
+ public Enumeration getAttributeNames(int arg0) {
+ // TODO Auto-generated method stub
+ return Collections.enumeration(getAttributesMap(arg0).keySet());
+ }
+
+ /* (non-Javadoc)
+ * @see javax.portlet.PortletSession#getCreationTime()
+ */
+ public long getCreationTime() {
+ // TODO Auto-generated method stub
+ return created;
+ }
+
+ /* (non-Javadoc)
+ * @see javax.portlet.PortletSession#getId()
+ */
+ public String getId() {
+ // TODO Auto-generated method stub
+ return ID;
+ }
+
+ /* (non-Javadoc)
+ * @see javax.portlet.PortletSession#getLastAccessedTime()
+ */
+ public long getLastAccessedTime() {
+ // TODO Auto-generated method stub
+ return 0;
+ }
+
+ /* (non-Javadoc)
+ * @see javax.portlet.PortletSession#getMaxInactiveInterval()
+ */
+ public int getMaxInactiveInterval() {
+ // TODO Auto-generated method stub
+ return maxInactive;
+ }
+
+ /* (non-Javadoc)
+ * @see javax.portlet.PortletSession#getPortletContext()
+ */
+ public PortletContext getPortletContext() {
+ // TODO Auto-generated method stub
+ return portletContext;
+ }
+
+ /* (non-Javadoc)
+ * @see javax.portlet.PortletSession#invalidate()
+ */
+ public void invalidate() {
+ // TODO Auto-generated method stub
+
+ }
+
+ /* (non-Javadoc)
+ * @see javax.portlet.PortletSession#isNew()
+ */
+ public boolean isNew() {
+ // TODO Auto-generated method stub
+ return false;
+ }
+
+ /* (non-Javadoc)
+ * @see javax.portlet.PortletSession#removeAttribute(java.lang.String)
+ */
+ public void removeAttribute(String arg0) {
+ removeAttribute(arg0, PORTLET_SCOPE);
+
+ }
+
+ /* (non-Javadoc)
+ * @see javax.portlet.PortletSession#removeAttribute(java.lang.String, int)
+ */
+ public void removeAttribute(String arg0, int arg1) {
+ getAttributesMap(arg1).remove(arg0);
+
+ }
+
+ /* (non-Javadoc)
+ * @see javax.portlet.PortletSession#setAttribute(java.lang.String, java.lang.Object)
+ */
+ public void setAttribute(String arg0, Object arg1) {
+ setAttribute(arg0, arg1, PORTLET_SCOPE);
+
+ }
+
+ /* (non-Javadoc)
+ * @see javax.portlet.PortletSession#setAttribute(java.lang.String, java.lang.Object,
int)
+ */
+ public void setAttribute(String arg0, Object arg1, int arg2) {
+ getAttributesMap(arg2).put(arg0, arg1);
+
+ }
+
+ /* (non-Javadoc)
+ * @see javax.portlet.PortletSession#setMaxInactiveInterval(int)
+ */
+ public void setMaxInactiveInterval(int arg0) {
+ maxInactive = arg0;
+ }
+
+}
Property changes on:
trunk/extensions/portletbridge/portletbridge-api/src/test/java/org/ajax4jsf/portlet/MockPortletSession.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Name: svn:keywords
+ Date Revision Author
Modified:
trunk/extensions/portletbridge/portletbridge-api/src/test/java/org/ajax4jsf/portlet/MockRenderRequest.java
===================================================================
---
trunk/extensions/portletbridge/portletbridge-api/src/test/java/org/ajax4jsf/portlet/MockRenderRequest.java 2008-01-16
01:30:07 UTC (rev 5403)
+++
trunk/extensions/portletbridge/portletbridge-api/src/test/java/org/ajax4jsf/portlet/MockRenderRequest.java 2008-01-16
01:35:34 UTC (rev 5404)
@@ -3,6 +3,7 @@
*/
package org.ajax4jsf.portlet;
+import javax.portlet.PortletContext;
import javax.portlet.RenderRequest;
/**
@@ -11,4 +12,9 @@
*/
public class MockRenderRequest extends MockPortletRequest implements
RenderRequest {
+
+ public MockRenderRequest(PortletContext portletContext) {
+ super(portletContext);
+ // TODO Auto-generated constructor stub
+ }
}
Modified: trunk/extensions/portletbridge/portletbridge-impl/pom.xml
===================================================================
--- trunk/extensions/portletbridge/portletbridge-impl/pom.xml 2008-01-16 01:30:07 UTC (rev
5403)
+++ trunk/extensions/portletbridge/portletbridge-impl/pom.xml 2008-01-16 01:35:34 UTC (rev
5404)
@@ -44,6 +44,32 @@
<optional>true</optional>
</dependency>
<dependency>
+ <groupId>javax.annotation</groupId>
+ <artifactId>jsr250-api</artifactId>
+ <version>1.0</version>
+ <optional>true</optional>
+ </dependency>
+ <dependency>
+ <groupId>javax.persistence</groupId>
+ <artifactId>persistence-api</artifactId>
+ <version>1.0</version>
+ <optional>true</optional>
+ </dependency>
+ <dependency>
+ <groupId>org.hibernate</groupId>
+ <artifactId>hibernate-commons-annotations</artifactId>
+ <version>3.3.0.ga</version>
+ <optional>true</optional>
+ <scope>provided</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.hibernate</groupId>
+ <artifactId>hibernate-annotations</artifactId>
+ <version>3.2.0.ga</version>
+ <optional>true</optional>
+ <scope>provided</scope>
+ </dependency>
+ <dependency>
<groupId>javax.transaction</groupId>
<artifactId>jta</artifactId>
<version>1.0.1B</version>
Added:
trunk/extensions/portletbridge/portletbridge-impl/src/main/java/org/ajax4jsf/portlet/seam/SeamPhaseListener.java
===================================================================
---
trunk/extensions/portletbridge/portletbridge-impl/src/main/java/org/ajax4jsf/portlet/seam/SeamPhaseListener.java
(rev 0)
+++
trunk/extensions/portletbridge/portletbridge-impl/src/main/java/org/ajax4jsf/portlet/seam/SeamPhaseListener.java 2008-01-16
01:35:34 UTC (rev 5404)
@@ -0,0 +1,608 @@
+/*
+ * JBoss, Home of Professional Open Source
+ *
+ * Distributable under LGPL license.
+ * See terms of license at
gnu.org.
+ */
+package org.ajax4jsf.portlet.seam;
+
+import static javax.faces.event.PhaseId.ANY_PHASE;
+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 java.lang.reflect.Method;
+import java.util.Map;
+
+import javax.faces.application.FacesMessage;
+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 org.jboss.seam.Seam;
+import org.jboss.seam.contexts.Context;
+import org.jboss.seam.contexts.Contexts;
+import org.jboss.seam.contexts.FacesLifecycle;
+import org.jboss.seam.core.ConversationList;
+import org.jboss.seam.core.ConversationPropagation;
+import org.jboss.seam.core.ConversationStack;
+import org.jboss.seam.core.Events;
+import org.jboss.seam.core.Init;
+import org.jboss.seam.core.Manager;
+import org.jboss.seam.exception.Exceptions;
+import org.jboss.seam.faces.FacesManager;
+import org.jboss.seam.faces.FacesMessages;
+import org.jboss.seam.faces.FacesPage;
+import org.jboss.seam.faces.Switcher;
+import org.jboss.seam.faces.Validation;
+import org.jboss.seam.log.LogProvider;
+import org.jboss.seam.log.Logging;
+import org.jboss.seam.navigation.Pages;
+import org.jboss.seam.pageflow.Pageflow;
+import org.jboss.seam.persistence.PersistenceContexts;
+import org.jboss.seam.transaction.Transaction;
+import org.jboss.seam.util.Reflections;
+
+/**
+ * Manages the Seam contexts associated with a JSF request
+ * throughout the lifecycle of the request. Performs
+ * transaction demarcation when Seam transaction management
+ * is enabled. Hacks the JSF lifecyle to provide page
+ * actions and page parameters.
+ *
+ * @author Gavin King
+ */
+public class SeamPhaseListener implements PhaseListener
+{
+ private static final long serialVersionUID = -9127555729455066493L;
+
+ private static final LogProvider log =
Logging.getLogProvider(SeamPhaseListener.class);
+
+ private static boolean exists = false;
+
+ private static final Method SET_RENDER_PARAMETER;
+ private static final Class ACTION_RESPONSE;
+ private static final Class PORTLET_REQUEST;
+
+ static
+ {
+ Method method = null;
+ Class actionResponseClass = null;
+ Class portletRequestClass = null;
+ try
+ {
+ Class[] parameterTypes = { String.class, String.class };
+ actionResponseClass = Class.forName("javax.portlet.ActionResponse");
+ portletRequestClass = Class.forName("javax.portlet.PortletRequest");
+ method = actionResponseClass.getMethod("setRenderParameter",
parameterTypes);
+ }
+ catch (Exception e) {}
+ SET_RENDER_PARAMETER = method;
+ ACTION_RESPONSE = actionResponseClass;
+ PORTLET_REQUEST = portletRequestClass;
+ }
+
+ public SeamPhaseListener()
+ {
+ if (exists)
+ {
+ log.warn("There should only be one Seam phase listener per
application");
+ }
+ exists=true;
+ }
+
+ public PhaseId getPhaseId()
+ {
+ return ANY_PHASE;
+ }
+
+ public void beforePhase(PhaseEvent event)
+ {
+ log.trace( "before phase: " + event.getPhaseId() );
+
+ FacesLifecycle.setPhaseId( event.getPhaseId() );
+
+ try
+ {
+ if ( isPortletRequest(event) )
+ {
+ beforePortletPhase(event);
+ }
+ else
+ {
+ beforeServletPhase(event);
+ }
+ raiseEventsBeforePhase(event);
+ }
+ catch (Exception e)
+ {
+ log.error("uncaught exception", e);
+ try
+ {
+ Exceptions.instance().handle(e);
+ }
+ catch (Exception ehe)
+ {
+ log.error("swallowing exception", e);
+ }
+ }
+
+ }
+
+ private void beforeServletPhase(PhaseEvent event)
+ {
+ if ( event.getPhaseId() == RESTORE_VIEW )
+ {
+ beforeRestoreView( event.getFacesContext() );
+ }
+
+ handleTransactionsBeforePhase(event);
+
+ if ( event.getPhaseId() == RENDER_RESPONSE )
+ {
+ beforeRenderResponse( event.getFacesContext() );
+ }
+
+ }
+
+ private void beforePortletPhase(PhaseEvent event)
+ {
+
+ FacesContext facesContext = event.getFacesContext();
+
+ if ( event.getPhaseId() == RESTORE_VIEW || event.getPhaseId() == RENDER_RESPONSE )
+ {
+ beforeRestoreView(facesContext);
+ }
+
+ //delegate to subclass:
+ handleTransactionsBeforePhase(event);
+
+ if ( event.getPhaseId() == RENDER_RESPONSE )
+ {
+ afterRestoreView(facesContext);
+ beforeRenderResponse( event.getFacesContext() );
+ }
+ }
+
+ public void afterPhase(PhaseEvent event)
+ {
+ log.trace( "after phase: " + event.getPhaseId() );
+
+ try
+ {
+ raiseEventsAfterPhase(event);
+ if ( isPortletRequest(event) )
+ {
+ afterPortletPhase(event);
+ }
+ else
+ {
+ afterServletPhase(event);
+ }
+ }
+ catch (Exception e)
+ {
+ log.error("uncaught exception", 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 ( event.getFacesContext().getResponseComplete() )
+ {
+ afterResponseComplete(event.getFacesContext());
+ }
+ }
+ catch (Exception ehe)
+ {
+ log.error("swallowing exception", e);
+ }
+ }
+
+ FacesLifecycle.clearPhaseId();
+
+ }
+
+ private void afterServletPhase(PhaseEvent event)
+ {
+
+ FacesContext facesContext = event.getFacesContext();
+
+ if ( event.getPhaseId() == RESTORE_VIEW )
+ {
+ afterRestoreView(facesContext);
+ }
+ else if ( event.getPhaseId() == INVOKE_APPLICATION )
+ {
+ afterInvokeApplication();
+ }
+ else if ( event.getPhaseId() == PROCESS_VALIDATIONS )
+ {
+ afterProcessValidations(facesContext);
+ }
+
+ //has to happen after, since restoreAnyConversationContext()
+ //can add messages
+ FacesMessages.afterPhase();
+
+ handleTransactionsAfterPhase(event);
+
+ if ( event.getPhaseId() == RENDER_RESPONSE )
+ {
+ afterRenderResponse(facesContext);
+ }
+ else if ( facesContext.getResponseComplete() )
+ {
+ afterResponseComplete(facesContext);
+ }
+ }
+
+ private void afterPortletPhase(PhaseEvent event)
+ {
+ FacesContext facesContext = event.getFacesContext();
+
+ if ( event.getPhaseId() == RESTORE_VIEW )
+ {
+ afterRestoreView(facesContext);
+ }
+ else if ( event.getPhaseId() == INVOKE_APPLICATION )
+ {
+ afterInvokeApplication();
+ }
+ else if ( event.getPhaseId() == PROCESS_VALIDATIONS )
+ {
+ afterProcessValidations(facesContext);
+ }
+
+ FacesMessages.afterPhase();
+
+ //delegate to subclass:
+ handleTransactionsAfterPhase(event);
+
+ if ( event.getPhaseId() == RENDER_RESPONSE )
+ {
+ //writeConversationIdToResponse( facesContext.getExternalContext().getResponse()
);
+ afterRenderResponse(facesContext);
+ }
+ else if ( event.getPhaseId() == INVOKE_APPLICATION ||
facesContext.getRenderResponse() || facesContext.getResponseComplete() )
+ {
+ Manager manager = Manager.instance();
+ manager.beforeRedirect();
+ if ( manager.isLongRunningConversation() )
+ {
+ setPortletRenderParameter(
+ facesContext.getExternalContext().getResponse(),
+ manager.getConversationIdParameter(),
+ manager.getCurrentConversationId()
+ );
+ }
+ afterResponseComplete(facesContext);
+ }
+
+ }
+
+ private static void setPortletRenderParameter(Object response, String
conversationIdParameter, String conversationId)
+ {
+ if ( ACTION_RESPONSE.isInstance(response) )
+ {
+ Reflections.invokeAndWrap(SET_RENDER_PARAMETER, response,
conversationIdParameter, conversationId);
+ }
+ }
+
+ private static boolean isPortletRequest(PhaseEvent event)
+ {
+ return PORTLET_REQUEST!=null &&
+ PORTLET_REQUEST.isInstance(
event.getFacesContext().getExternalContext().getRequest() );
+ }
+
+ public void handleTransactionsBeforePhase(PhaseEvent event)
+ {
+ if ( Init.instance().isTransactionManagementEnabled() )
+ {
+ PhaseId phaseId = event.getPhaseId();
+ boolean beginTran = phaseId == PhaseId.RENDER_RESPONSE ||
+ phaseId == ( Transaction.instance().isConversationContextRequired() ?
PhaseId.APPLY_REQUEST_VALUES : PhaseId.RESTORE_VIEW );
+ //( phaseId == PhaseId.RENDER_RESPONSE &&
!Init.instance().isClientSideConversations() );
+
+ if (beginTran)
+ {
+ begin(phaseId);
+ }
+ }
+ }
+
+ public void handleTransactionsAfterPhase(PhaseEvent event)
+ {
+ if ( Init.instance().isTransactionManagementEnabled() )
+ {
+ PhaseId phaseId = event.getPhaseId();
+ boolean commitTran = phaseId == PhaseId.INVOKE_APPLICATION ||
+ event.getFacesContext().getRenderResponse() || //TODO: no need to commit
the tx if we failed to restore the view
+ event.getFacesContext().getResponseComplete() ||
+ phaseId == PhaseId.RENDER_RESPONSE;
+ //( phaseId == PhaseId.RENDER_RESPONSE &&
!Init.instance().isClientSideConversations() );
+
+ if (commitTran)
+ {
+ commitOrRollback(phaseId); //we commit before destroying contexts, cos the
contexts have the PC in them
+ }
+ }
+ }
+
+ protected void handleTransactionsAfterPageActions(FacesContext facesContext)
+ {
+ if ( Init.instance().isTransactionManagementEnabled() )
+ {
+ commitOrRollback(PhaseId.INVOKE_APPLICATION);
+ if ( !facesContext.getResponseComplete() )
+ {
+ begin(PhaseId.INVOKE_APPLICATION);
+ }
+ }
+ }
+
+ protected void afterInvokeApplication()
+ {
+ if ( Init.instance().isTransactionManagementEnabled() )
+ {
+ addTransactionFailedMessage();
+ }
+ }
+
+ protected void afterProcessValidations(FacesContext facesContext)
+ {
+ Validation.instance().afterProcessValidations(facesContext);
+ }
+
+ /**
+ * Set up the Seam contexts, except for the conversation
+ * context
+ */
+ protected void beforeRestoreView(FacesContext facesContext)
+ {
+ FacesLifecycle.beginRequest( facesContext.getExternalContext() );
+ }
+
+ /**
+ * Restore the page and conversation contexts during a JSF request
+ */
+ protected void afterRestoreView(FacesContext facesContext)
+ {
+ FacesLifecycle.resumePage();
+ Map parameters = facesContext.getExternalContext().getRequestParameterMap();
+ ConversationPropagation.instance().restoreConversationId(parameters);
+ boolean conversationFound = Manager.instance().restoreConversation();
+ FacesLifecycle.resumeConversation( facesContext.getExternalContext() );
+ postRestorePage(facesContext, parameters, conversationFound);
+ }
+
+ public void raiseEventsBeforePhase(PhaseEvent event)
+ {
+ if ( Contexts.isApplicationContextActive() )
+ {
+ Events.instance().raiseEvent("org.jboss.seam.beforePhase", event);
+ }
+
+ /*if ( Contexts.isConversationContextActive() &&
Init.instance().isJbpmInstalled() && Pageflow.instance().isInProcess() )
+ {
+ String name;
+ PhaseId phaseId = event.getPhaseId();
+ if ( phaseId == PhaseId.PROCESS_VALIDATIONS )
+ {
+ name = "process-validations";
+ }
+ else if ( phaseId == PhaseId.UPDATE_MODEL_VALUES )
+ {
+ name = "update-model-values";
+ }
+ else if ( phaseId == PhaseId.INVOKE_APPLICATION )
+ {
+ name = "invoke-application";
+ }
+ else if ( phaseId == PhaseId.RENDER_RESPONSE )
+ {
+ name = "render-response";
+ }
+ else
+ {
+ return;
+ }
+ Pageflow.instance().processEvents(name);
+ }*/
+ }
+
+ public void raiseEventsAfterPhase(PhaseEvent event)
+ {
+ if ( Contexts.isApplicationContextActive() )
+ {
+ Events.instance().raiseEvent("org.jboss.seam.afterPhase", event);
+ }
+ }
+
+ /**
+ * Add a faces message when Seam-managed transactions fail.
+ */
+ protected void addTransactionFailedMessage()
+ {
+ try
+ {
+ if ( Transaction.instance().isRolledBackOrMarkedRollback() )
+ {
+ FacesMessages.instance().addFromResourceBundleOrDefault(
+ FacesMessage.SEVERITY_WARN,
+ "org.jboss.seam.TransactionFailed",
+ "Transaction failed"
+ );
+ }
+ }
+ catch (Exception e) {} //swallow silently, not important
+ }
+
+ protected void beforeRenderResponse(FacesContext facesContext)
+ {
+
+ if ( Contexts.isPageContextActive() )
+ {
+ Context pageContext = Contexts.getPageContext();
+ //after every time that the view may have changed,
+ //we need to flush the page context, since the
+ //attribute map is being discarder
+ pageContext.flush();
+ //force refresh of the conversation lists (they are kept in PAGE context)
+ pageContext.remove(Seam.getComponentName(Switcher.class));
+ pageContext.remove("org.jboss.seam.core.conversationList");
+ pageContext.remove("org.jboss.seam.core.conversationStack");
+ }
+
+ preRenderPage(facesContext);
+
+ if ( facesContext.getResponseComplete() )
+ {
+ //workaround for a bug in MyFaces prior to 1.1.3
+ if ( Init.instance().isMyFacesLifecycleBug() )
+ {
+ FacesLifecycle.endRequest( facesContext.getExternalContext() );
+ }
+ }
+ else //if the page actions did not call responseComplete()
+ {
+ FacesMessages.instance().beforeRenderResponse();
+ //do this both before and after render, since conversations
+ //and pageflows can begin during render
+ FacesManager.instance().prepareBackswitch(facesContext);
+ }
+
+ FacesPage.instance().storeConversation();
+ FacesPage.instance().storePageflow();
+
+ PersistenceContexts persistenceContexts = PersistenceContexts.instance();
+ if (persistenceContexts != null)
+ {
+ persistenceContexts.beforeRender();
+ }
+ }
+
+ protected void afterRenderResponse(FacesContext facesContext)
+ {
+ //do this both before and after render, since conversations
+ //and pageflows can begin during render
+ FacesManager.instance().prepareBackswitch(facesContext);
+
+ PersistenceContexts persistenceContexts = PersistenceContexts.instance();
+ if (persistenceContexts != null)
+ {
+ persistenceContexts.afterRender();
+ }
+
+ ExternalContext externalContext = facesContext.getExternalContext();
+ Manager.instance().endRequest( externalContext.getSessionMap() );
+ FacesLifecycle.endRequest(externalContext);
+ }
+
+ protected void afterResponseComplete(FacesContext facesContext)
+ {
+ //responseComplete() was called by one of the other phases,
+ //so we will never get to the RENDER_RESPONSE phase
+ //Note: we can't call Manager.instance().beforeRedirect() here,
+ //since a redirect is not the only reason for a responseComplete
+ ExternalContext externalContext = facesContext.getExternalContext();
+ Manager.instance().endRequest( externalContext.getSessionMap() );
+ FacesLifecycle.endRequest( facesContext.getExternalContext() );
+ }
+
+ private void postRestorePage(FacesContext facesContext, Map parameters, boolean
conversationFound)
+ {
+ if ( !Pages.isDebugPage() )
+ {
+ // Only redirect to no-conversation-view if a login redirect isn't required
+ if (!conversationFound &&
!Pages.instance().isLoginRedirectRequired(facesContext))
+ {
+ Pages.instance().redirectToNoConversationView();
+ }
+
+ Manager.instance().handleConversationPropagation(parameters);
+
+ if ( Init.instance().isJbpmInstalled() && !isExceptionHandlerRedirect()
)
+ {
+ Pageflow.instance().validatePageflow(facesContext);
+ }
+
+ Pages.instance().postRestore(facesContext);
+ }
+ }
+
+ private boolean preRenderPage(FacesContext facesContext)
+ {
+ if ( Pages.isDebugPage() )
+ {
+ return false;
+ }
+ else
+ {
+ FacesLifecycle.setPhaseId(PhaseId.INVOKE_APPLICATION);
+ boolean actionsWereCalled = false;
+ try
+ {
+ actionsWereCalled = Pages.instance().preRender(facesContext);
+ return actionsWereCalled;
+ }
+ finally
+ {
+ FacesLifecycle.setPhaseId(PhaseId.RENDER_RESPONSE);
+ if (actionsWereCalled)
+ {
+ FacesMessages.afterPhase();
+ handleTransactionsAfterPageActions(facesContext); //TODO: does it really
belong in the finally?
+ }
+ }
+ }
+ }
+
+ private boolean isExceptionHandlerRedirect()
+ {
+ return
Contexts.getConversationContext().isSet("org.jboss.seam.handledException");
+ }
+
+ void begin(PhaseId phaseId)
+ {
+ try
+ {
+ if ( !Transaction.instance().isActiveOrMarkedRollback() )
+ {
+ log.debug("beginning transaction prior to phase: " + phaseId);
+ Transaction.instance().begin();
+ }
+ }
+ catch (Exception e)
+ {
+ throw new IllegalStateException("Could not start transaction", e);
+ }
+ }
+
+ void commitOrRollback(PhaseId phaseId)
+ {
+ try
+ {
+ if ( Transaction.instance().isActive() )
+ {
+ log.debug("committing transaction after phase: " + phaseId);
+ Transaction.instance().commit();
+ }
+ else if ( Transaction.instance().isRolledBackOrMarkedRollback() )
+ {
+ log.debug("rolling back transaction after phase: " + phaseId);
+ Transaction.instance().rollback();
+ }
+ }
+ catch (Exception e)
+ {
+ throw new IllegalStateException("Could not commit transaction", e);
+ }
+ }
+
+}
Property changes on:
trunk/extensions/portletbridge/portletbridge-impl/src/main/java/org/ajax4jsf/portlet/seam/SeamPhaseListener.java
___________________________________________________________________
Name: svn:executable
+ *
Name: svn:mime-type
+ text/plain
Name: svn:keywords
+ Date Revision Author
Modified:
trunk/extensions/portletbridge/portletbridge-impl/src/test/java/org/ajax4jsf/portlet/context/ContextFactoryTest.java
===================================================================
---
trunk/extensions/portletbridge/portletbridge-impl/src/test/java/org/ajax4jsf/portlet/context/ContextFactoryTest.java 2008-01-16
01:30:07 UTC (rev 5403)
+++
trunk/extensions/portletbridge/portletbridge-impl/src/test/java/org/ajax4jsf/portlet/context/ContextFactoryTest.java 2008-01-16
01:35:34 UTC (rev 5404)
@@ -60,8 +60,8 @@
*/
public void testGetFacesContextPortlet() {
FacesContextFactoryImpl factory = new FacesContextFactoryImpl(facesContextFactory);
- MockPortletContext portletContext = new MockPortletContext();
- MockActionRequest portletRequest = new MockActionRequest();
+ MockPortletContext portletContext = new MockPortletContext(servletContext);
+ MockActionRequest portletRequest = new MockActionRequest(portletContext);
MockActionResponse portletResponse = new MockActionResponse();
FacesContext context = factory.getFacesContext(portletContext,
portletRequest, portletResponse, lifecycle);
Modified:
trunk/extensions/portletbridge/portletbridge-impl/src/test/java/org/ajax4jsf/portlet/context/PortletExternalContextTest.java
===================================================================
---
trunk/extensions/portletbridge/portletbridge-impl/src/test/java/org/ajax4jsf/portlet/context/PortletExternalContextTest.java 2008-01-16
01:30:07 UTC (rev 5403)
+++
trunk/extensions/portletbridge/portletbridge-impl/src/test/java/org/ajax4jsf/portlet/context/PortletExternalContextTest.java 2008-01-16
01:35:34 UTC (rev 5404)
@@ -34,8 +34,8 @@
*/
public void setUp() throws Exception {
super.setUp();
- portletContext=new MockPortletContext();
- portletRequest = new MockActionRequest();
+ portletContext=new MockPortletContext(servletContext);
+ portletRequest = new MockActionRequest(portletContext);
portletResponse = new MockActionResponse();
portletContextImpl = new
PortletExternalContextImpl(portletContext,portletRequest,portletResponse);
portalFacesContext = new FacesContextImpl(portletContextImpl,lifecycle);
Added:
trunk/extensions/portletbridge/portletbridge-impl/src/test/java/org/ajax4jsf/portlet/seam/AbstractSeamPortletTestCase.java
===================================================================
---
trunk/extensions/portletbridge/portletbridge-impl/src/test/java/org/ajax4jsf/portlet/seam/AbstractSeamPortletTestCase.java
(rev 0)
+++
trunk/extensions/portletbridge/portletbridge-impl/src/test/java/org/ajax4jsf/portlet/seam/AbstractSeamPortletTestCase.java 2008-01-16
01:35:34 UTC (rev 5404)
@@ -0,0 +1,87 @@
+/**
+ *
+ */
+package org.ajax4jsf.portlet.seam;
+
+import javax.faces.context.ExternalContext;
+import javax.faces.context.FacesContext;
+import javax.portlet.faces.Bridge;
+
+import org.ajax4jsf.portlet.AbstractAjax4jsfPortletTestCase;
+import org.ajax4jsf.portlet.AjaxPortletBridge;
+import org.jboss.seam.Component;
+import org.jboss.seam.Seam;
+import org.jboss.seam.contexts.ApplicationContext;
+import org.jboss.seam.contexts.Context;
+import org.jboss.seam.contexts.TestLifecycle;
+import org.jboss.seam.core.Conversation;
+import org.jboss.seam.core.ConversationEntries;
+import org.jboss.seam.core.ConversationPropagation;
+import org.jboss.seam.core.Events;
+import org.jboss.seam.core.Init;
+import org.jboss.seam.core.ResourceLoader;
+import org.jboss.seam.faces.FacesManager;
+import org.jboss.seam.faces.FacesMessages;
+import org.jboss.seam.faces.FacesPage;
+import org.jboss.seam.faces.Validation;
+import org.jboss.seam.navigation.Pages;
+import org.jboss.seam.web.Session;
+
+/**
+ * @author asmirnov
+ *
+ */
+public abstract class AbstractSeamPortletTestCase extends
+ AbstractAjax4jsfPortletTestCase {
+
+ protected Bridge portletBridge;
+
+ public AbstractSeamPortletTestCase(String name) {
+ super(name);
+ }
+
+ @Override
+ public void setUp() throws Exception {
+ super.setUp();
+ ExternalContext externalContext = setupRequest();
+ facesContext.setExternalContext(externalContext);
+ portletBridge = new AjaxPortletBridge();
+ portletBridge.init(portletConfig);
+ Context appContext = new ApplicationContext( externalContext.getApplicationMap()
);
+ installComponents(appContext);
+ }
+
+ protected abstract ExternalContext setupRequest();
+
+ @Override
+ public void tearDown() throws Exception {
+ TestLifecycle.endTest();
+ super.tearDown();
+ portletBridge = null;
+ }
+
+ protected void installComponents(Context appContext)
+ {
+ Init init = new Init();
+ init.setTransactionManagementEnabled(true);
+ appContext.set( Seam.getComponentName(Init.class), init );
+ installComponent(appContext, MockUserTransaction.class);
+ installComponent(appContext, FacesManager.class);
+ installComponent(appContext, ConversationEntries.class);
+ installComponent(appContext, FacesPage.class);
+ installComponent(appContext, Conversation.class);
+ installComponent(appContext, FacesMessages.class);
+ installComponent(appContext, Pages.class);
+ installComponent(appContext, Events.class);
+ installComponent(appContext, Validation.class);
+ installComponent(appContext, Session.class);
+ installComponent(appContext, ConversationPropagation.class);
+ installComponent(appContext, ResourceLoader.class);
+ }
+
+ protected void installComponent(Context appContext, Class clazz)
+ {
+ appContext.set( Seam.getComponentName(clazz) + ".component", new
Component(clazz) );
+ }
+
+}
Property changes on:
trunk/extensions/portletbridge/portletbridge-impl/src/test/java/org/ajax4jsf/portlet/seam/AbstractSeamPortletTestCase.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Name: svn:keywords
+ Date Revision Author
Added:
trunk/extensions/portletbridge/portletbridge-impl/src/test/java/org/ajax4jsf/portlet/seam/MockUserTransaction.java
===================================================================
---
trunk/extensions/portletbridge/portletbridge-impl/src/test/java/org/ajax4jsf/portlet/seam/MockUserTransaction.java
(rev 0)
+++
trunk/extensions/portletbridge/portletbridge-impl/src/test/java/org/ajax4jsf/portlet/seam/MockUserTransaction.java 2008-01-16
01:35:34 UTC (rev 5404)
@@ -0,0 +1,115 @@
+/**
+ *
+ */
+package org.ajax4jsf.portlet.seam;
+
+import static org.jboss.seam.annotations.Install.FRAMEWORK;
+
+import javax.persistence.EntityManager;
+import javax.transaction.HeuristicMixedException;
+import javax.transaction.HeuristicRollbackException;
+import javax.transaction.NotSupportedException;
+import javax.transaction.RollbackException;
+import javax.transaction.Status;
+import javax.transaction.Synchronization;
+import javax.transaction.SystemException;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.jboss.seam.ScopeType;
+import org.jboss.seam.annotations.Install;
+import org.jboss.seam.annotations.Name;
+import org.jboss.seam.annotations.Scope;
+import org.jboss.seam.annotations.intercept.BypassInterceptors;
+import org.jboss.seam.transaction.AbstractUserTransaction;
+
+/**
+ * @author asmirnov
+ *
+ */
+(a)Name("org.jboss.seam.transaction.transaction")
+(a)Scope(ScopeType.EVENT)
+@Install(value = false, precedence = FRAMEWORK)
+@BypassInterceptors
+public class MockUserTransaction extends AbstractUserTransaction {
+
+ private static final Log _log = LogFactory.getLog(MockUserTransaction.class);
+
+ private int status = Status.STATUS_NO_TRANSACTION;
+
+ /* (non-Javadoc)
+ * @see
org.jboss.seam.transaction.AbstractUserTransaction#registerSynchronization(javax.transaction.Synchronization)
+ */
+ @Override
+ public void registerSynchronization(Synchronization arg0) {
+ _log.info("registerSyncronisation");
+ // TODO Auto-generated method stub
+ }
+
+ /* (non-Javadoc)
+ * @see javax.transaction.UserTransaction#begin()
+ */
+ public void begin() throws NotSupportedException, SystemException {
+ _log.info("Transaction begin");
+ if(status != Status.STATUS_NO_TRANSACTION){
+ throw new SystemException("Transaction already active");
+ }
+ status = Status.STATUS_ACTIVE;
+ }
+
+ /* (non-Javadoc)
+ * @see javax.transaction.UserTransaction#commit()
+ */
+ public void commit() throws RollbackException, HeuristicMixedException,
+ HeuristicRollbackException, SecurityException,
+ IllegalStateException, SystemException {
+ _log.info("Transaction commit");
+ if(status != Status.STATUS_ACTIVE){
+ throw new SystemException("Transaction not active");
+ }
+ status = Status.STATUS_COMMITTED;
+ }
+
+ /* (non-Javadoc)
+ * @see javax.transaction.UserTransaction#getStatus()
+ */
+ public int getStatus() throws SystemException {
+ // TODO Auto-generated method stub
+ return status;
+ }
+
+ /* (non-Javadoc)
+ * @see javax.transaction.UserTransaction#rollback()
+ */
+ public void rollback() throws IllegalStateException, SecurityException,
+ SystemException {
+ _log.info("transaction rollback");
+ if(status != Status.STATUS_ACTIVE){
+ throw new SystemException("Transaction not active");
+ }
+ status = Status.STATUS_ROLLEDBACK;
+ }
+
+ /* (non-Javadoc)
+ * @see javax.transaction.UserTransaction#setRollbackOnly()
+ */
+ public void setRollbackOnly() throws IllegalStateException, SystemException {
+ _log.info("Transaction set to rollback only");
+ status = Status.STATUS_MARKED_ROLLBACK;
+
+ }
+
+ /* (non-Javadoc)
+ * @see javax.transaction.UserTransaction#setTransactionTimeout(int)
+ */
+ public void setTransactionTimeout(int arg0) throws SystemException {
+ // TODO Auto-generated method stub
+
+ }
+
+ @Override
+ public void enlist(EntityManager entityManager) throws SystemException {
+ _log.info("Transaction enlist");
+ // do nothing
+ }
+}
Property changes on:
trunk/extensions/portletbridge/portletbridge-impl/src/test/java/org/ajax4jsf/portlet/seam/MockUserTransaction.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Name: svn:keywords
+ Date Revision Author
Added:
trunk/extensions/portletbridge/portletbridge-impl/src/test/java/org/ajax4jsf/portlet/seam/PhaseListenerActionPhaseTest.java
===================================================================
---
trunk/extensions/portletbridge/portletbridge-impl/src/test/java/org/ajax4jsf/portlet/seam/PhaseListenerActionPhaseTest.java
(rev 0)
+++
trunk/extensions/portletbridge/portletbridge-impl/src/test/java/org/ajax4jsf/portlet/seam/PhaseListenerActionPhaseTest.java 2008-01-16
01:35:34 UTC (rev 5404)
@@ -0,0 +1,75 @@
+/**
+ *
+ */
+package org.ajax4jsf.portlet.seam;
+
+import javax.faces.context.ExternalContext;
+import javax.faces.event.PhaseEvent;
+import javax.faces.event.PhaseId;
+import javax.portlet.faces.Bridge;
+
+import org.ajax4jsf.portlet.context.AbstractExternalContext;
+import org.ajax4jsf.portlet.context.PortletExternalContextImpl;
+import org.jboss.seam.contexts.Contexts;
+
+/**
+ * @author asmirnov
+ *
+ */
+public class PhaseListenerActionPhaseTest extends AbstractSeamPortletTestCase {
+
+ private SeamPhaseListener phaseListener;
+ /**
+ * @param name
+ */
+ public PhaseListenerActionPhaseTest(String name) {
+ super(name);
+ }
+
+ /* (non-Javadoc)
+ * @see org.ajax4jsf.portlet.seam.AbstractSeamPortletTestCase#setUp()
+ */
+ public void setUp() throws Exception {
+ super.setUp();
+ phaseListener = new SeamPhaseListener();
+ lifecycle.addPhaseListener(phaseListener);
+ }
+
+ /* (non-Javadoc)
+ * @see org.ajax4jsf.portlet.seam.AbstractSeamPortletTestCase#tearDown()
+ */
+ public void tearDown() throws Exception {
+ super.tearDown();
+ phaseListener = null;
+ }
+
+ /**
+ * Test method for {@link
org.ajax4jsf.portlet.seam.SeamPhaseListener#beforePhase(javax.faces.event.PhaseEvent)}.
+ */
+ public void testBeforePhase() {
+ assertFalse(Contexts.isEventContextActive());
+ phaseListener.beforePhase(new
PhaseEvent(facesContext,PhaseId.RESTORE_VIEW,lifecycle));
+ assertTrue(Contexts.isEventContextActive());
+ }
+
+ /**
+ * Test method for {@link
org.ajax4jsf.portlet.seam.SeamPhaseListener#afterPhase(javax.faces.event.PhaseEvent)}.
+ */
+ public void testAfterPhase() {
+ assertFalse(Contexts.isEventContextActive());
+ phaseListener.beforePhase(new
PhaseEvent(facesContext,PhaseId.RESTORE_VIEW,lifecycle));
+ phaseListener.afterPhase(new PhaseEvent(facesContext,PhaseId.RESTORE_VIEW,lifecycle));
+ assertTrue(Contexts.isEventContextActive());
+ }
+
+ @Override
+ protected ExternalContext setupRequest() {
+ setupActionRequest();
+ request.setAttribute(Bridge.PORTLET_LIFECYCLE_PHASE, Bridge.PortletPhase.ActionPhase);
+ request.setAttribute(AbstractExternalContext.PORTLET_CONFIG_ATTRIBUTE,
+ portletConfig);
+
+ return new PortletExternalContextImpl(portletContext,actionRequest,actionResponse);
+ }
+
+}
Property changes on:
trunk/extensions/portletbridge/portletbridge-impl/src/test/java/org/ajax4jsf/portlet/seam/PhaseListenerActionPhaseTest.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Name: svn:keywords
+ Date Revision Author
Modified: trunk/samples/scrollableDataTableDemo/src/main/webapp/WEB-INF/web.xml
===================================================================
--- trunk/samples/scrollableDataTableDemo/src/main/webapp/WEB-INF/web.xml 2008-01-16
01:30:07 UTC (rev 5403)
+++ trunk/samples/scrollableDataTableDemo/src/main/webapp/WEB-INF/web.xml 2008-01-16
01:35:34 UTC (rev 5404)
@@ -36,7 +36,8 @@
<filter>
<display-name>Ajax4jsf Filter</display-name>
<filter-name>ajax4jsf</filter-name>
- <filter-class>org.ajax4jsf.FastFilter</filter-class>
+ <filter-class>org.ajax4jsf.FastFilter</filter-class>
+
<init-param><param-name>enable-cache</param-name><param-value>false</param-value></init-param>
</filter>
<filter>
<display-name>Request Metrics</display-name>
Added:
trunk/samples/seamPortletEar/seamBookingPortlet/src/main/java/org/ajax4jsf/portlet/seam/SeamPhaseListener.java
===================================================================
---
trunk/samples/seamPortletEar/seamBookingPortlet/src/main/java/org/ajax4jsf/portlet/seam/SeamPhaseListener.java
(rev 0)
+++
trunk/samples/seamPortletEar/seamBookingPortlet/src/main/java/org/ajax4jsf/portlet/seam/SeamPhaseListener.java 2008-01-16
01:35:34 UTC (rev 5404)
@@ -0,0 +1,629 @@
+/*
+ * JBoss, Home of Professional Open Source
+ *
+ * Distributable under LGPL license.
+ * See terms of license at
gnu.org.
+ */
+package org.ajax4jsf.portlet.seam;
+
+import static javax.faces.event.PhaseId.ANY_PHASE;
+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 java.lang.reflect.Method;
+import java.util.Map;
+
+import javax.faces.application.FacesMessage;
+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 org.jboss.seam.Seam;
+import org.jboss.seam.contexts.Context;
+import org.jboss.seam.contexts.Contexts;
+import org.jboss.seam.contexts.FacesLifecycle;
+import org.jboss.seam.core.ConversationList;
+import org.jboss.seam.core.ConversationPropagation;
+import org.jboss.seam.core.ConversationStack;
+import org.jboss.seam.core.Events;
+import org.jboss.seam.core.Init;
+import org.jboss.seam.core.Manager;
+import org.jboss.seam.exception.Exceptions;
+import org.jboss.seam.faces.FacesManager;
+import org.jboss.seam.faces.FacesMessages;
+import org.jboss.seam.faces.FacesPage;
+import org.jboss.seam.faces.Switcher;
+import org.jboss.seam.faces.Validation;
+import org.jboss.seam.log.LogProvider;
+import org.jboss.seam.log.Logging;
+import org.jboss.seam.navigation.Pages;
+import org.jboss.seam.pageflow.Pageflow;
+import org.jboss.seam.persistence.PersistenceContexts;
+import org.jboss.seam.transaction.Transaction;
+import org.jboss.seam.util.Reflections;
+
+/**
+ * Manages the Seam contexts associated with a JSF request
+ * throughout the lifecycle of the request. Performs
+ * transaction demarcation when Seam transaction management
+ * is enabled. Hacks the JSF lifecyle to provide page
+ * actions and page parameters.
+ *
+ * @author Gavin King
+ */
+public class SeamPhaseListener implements PhaseListener
+{
+ public static final String JAVAX_PORTLET_FACES_PHASE =
"javax.portlet.faces.phase";
+
+private static final long serialVersionUID = -9127555729455066493L;
+
+ private static final LogProvider log =
Logging.getLogProvider(SeamPhaseListener.class);
+
+ private static boolean exists = false;
+
+ private static final Method SET_RENDER_PARAMETER;
+ private static final Class ACTION_RESPONSE;
+ private static final Class PORTLET_REQUEST;
+
+ static
+ {
+ Method method = null;
+ Class actionResponseClass = null;
+ Class portletRequestClass = null;
+ try
+ {
+ Class[] parameterTypes = { String.class, String.class };
+ actionResponseClass = Class.forName("javax.portlet.ActionResponse");
+ portletRequestClass = Class.forName("javax.portlet.PortletRequest");
+ method = actionResponseClass.getMethod("setRenderParameter",
parameterTypes);
+ }
+ catch (Exception e) {}
+ SET_RENDER_PARAMETER = method;
+ ACTION_RESPONSE = actionResponseClass;
+ PORTLET_REQUEST = portletRequestClass;
+ }
+
+ public SeamPhaseListener()
+ {
+ if (exists)
+ {
+ log.warn("There should only be one Seam phase listener per
application");
+ }
+ exists=true;
+ }
+
+ public PhaseId getPhaseId()
+ {
+ return ANY_PHASE;
+ }
+
+ public void beforePhase(PhaseEvent event)
+ {
+ log.trace( "before phase: " + event.getPhaseId() );
+
+ FacesLifecycle.setPhaseId( event.getPhaseId() );
+
+ try
+ {
+ if ( isPortletRequest(event) )
+ {
+ beforePortletPhase(event);
+ }
+ else
+ {
+ beforeServletPhase(event);
+ }
+ raiseEventsBeforePhase(event);
+ }
+ catch (Exception e)
+ {
+ log.error("uncaught exception", e);
+ try
+ {
+ Exceptions.instance().handle(e);
+ }
+ catch (Exception ehe)
+ {
+ log.error("swallowing exception", e);
+ }
+ }
+
+ }
+
+ private void beforeServletPhase(PhaseEvent event)
+ {
+ if ( event.getPhaseId() == RESTORE_VIEW )
+ {
+ beforeRestoreView( event.getFacesContext() );
+ }
+
+ handleTransactionsBeforePhase(event);
+
+ if ( event.getPhaseId() == RENDER_RESPONSE )
+ {
+ beforeRenderResponse( event.getFacesContext() );
+ }
+
+ }
+
+ private void beforePortletPhase(PhaseEvent event)
+ {
+ // Changed to compability with JSR-301 portlet bridhe
+ FacesContext facesContext = event.getFacesContext();
+
+ if ( event.getPhaseId() == RESTORE_VIEW /*|| event.getPhaseId() ==
RENDER_RESPONSE*/ )
+ {
+ beforeRestoreView(facesContext);
+ }
+
+ if (!Contexts.isApplicationContextActive()) {
+ beforeRestoreView(facesContext);
+ afterRestoreView(facesContext);
+ }
+
+ //delegate to subclass:
+ handleTransactionsBeforePhase(event);
+
+ if ( event.getPhaseId() == RENDER_RESPONSE )
+ {
+// afterRestoreView(facesContext);
+ beforeRenderResponse( event.getFacesContext() );
+ }
+ }
+
+ public void afterPhase(PhaseEvent event)
+ {
+ log.trace( "after phase: " + event.getPhaseId() );
+
+ try
+ {
+ raiseEventsAfterPhase(event);
+ if ( isPortletRequest(event) )
+ {
+ afterPortletPhase(event);
+ }
+ else
+ {
+ afterServletPhase(event);
+ }
+ }
+ catch (Exception e)
+ {
+ log.error("uncaught exception", 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 ( event.getFacesContext().getResponseComplete() )
+ {
+ afterResponseComplete(event.getFacesContext());
+ }
+ }
+ catch (Exception ehe)
+ {
+ log.error("swallowing exception", e);
+ }
+ }
+
+ FacesLifecycle.clearPhaseId();
+
+ }
+
+ private void afterServletPhase(PhaseEvent event)
+ {
+
+ FacesContext facesContext = event.getFacesContext();
+
+ if ( event.getPhaseId() == RESTORE_VIEW )
+ {
+ afterRestoreView(facesContext);
+ }
+ else if ( event.getPhaseId() == INVOKE_APPLICATION )
+ {
+ afterInvokeApplication();
+ }
+ else if ( event.getPhaseId() == PROCESS_VALIDATIONS )
+ {
+ afterProcessValidations(facesContext);
+ }
+
+ //has to happen after, since restoreAnyConversationContext()
+ //can add messages
+ FacesMessages.afterPhase();
+
+ handleTransactionsAfterPhase(event);
+
+ if ( event.getPhaseId() == RENDER_RESPONSE )
+ {
+ afterRenderResponse(facesContext);
+ }
+ else if ( facesContext.getResponseComplete() )
+ {
+ afterResponseComplete(facesContext);
+ }
+ }
+
+ private void afterPortletPhase(PhaseEvent event)
+ {
+ FacesContext facesContext = event.getFacesContext();
+
+ if ( event.getPhaseId() == RESTORE_VIEW )
+ {
+ afterRestoreView(facesContext);
+ }
+ else if ( event.getPhaseId() == INVOKE_APPLICATION )
+ {
+ afterInvokeApplication();
+ }
+ else if ( event.getPhaseId() == PROCESS_VALIDATIONS )
+ {
+ afterProcessValidations(facesContext);
+ }
+
+ FacesMessages.afterPhase();
+
+
+ Object bridgePhase =
facesContext.getExternalContext().getRequestMap().get(JAVAX_PORTLET_FACES_PHASE);
+
+
+ if ( event.getPhaseId() == RENDER_RESPONSE )
+ {
+ //delegate to subclass:
+ handleTransactionsAfterPhase(event);
+ //writeConversationIdToResponse( facesContext.getExternalContext().getResponse()
);
+ afterRenderResponse(facesContext);
+ }
+ else if ( (null == bridgePhase ||
"ActionPhase".equals(bridgePhase.toString())) && (event.getPhaseId() ==
INVOKE_APPLICATION || facesContext.getRenderResponse() ||
facesContext.getResponseComplete()) )
+ {
+ preRenderPage(facesContext, event.getPhaseId());
+ //delegate to subclass:
+ handleTransactionsAfterPhase(event);
+ Manager manager = Manager.instance();
+ manager.beforeRedirect();
+ if ( manager.isLongRunningConversation() )
+ {
+ setPortletRenderParameter(
+ facesContext.getExternalContext().getResponse(),
+ manager.getConversationIdParameter(),
+ manager.getCurrentConversationId()
+ );
+ }
+ afterResponseComplete(facesContext);
+ } else {
+ //delegate to subclass:
+ handleTransactionsAfterPhase(event);
+ }
+
+ }
+
+ private static void setPortletRenderParameter(Object response, String
conversationIdParameter, String conversationId)
+ {
+ if ( ACTION_RESPONSE.isInstance(response) )
+ {
+ Reflections.invokeAndWrap(SET_RENDER_PARAMETER, response,
conversationIdParameter, conversationId);
+ }
+ }
+
+ private static boolean isPortletRequest(PhaseEvent event)
+ {
+ return PORTLET_REQUEST!=null &&
+ PORTLET_REQUEST.isInstance(
event.getFacesContext().getExternalContext().getRequest() );
+ }
+
+ public void handleTransactionsBeforePhase(PhaseEvent event)
+ {
+ if ( Init.instance().isTransactionManagementEnabled() )
+ {
+ PhaseId phaseId = event.getPhaseId();
+ boolean beginTran = phaseId == PhaseId.RENDER_RESPONSE ||
+ phaseId == ( Transaction.instance().isConversationContextRequired() ?
PhaseId.APPLY_REQUEST_VALUES : PhaseId.RESTORE_VIEW );
+ //( phaseId == PhaseId.RENDER_RESPONSE &&
!Init.instance().isClientSideConversations() );
+
+ if (beginTran)
+ {
+ begin(phaseId);
+ }
+ }
+ }
+
+ public void handleTransactionsAfterPhase(PhaseEvent event)
+ {
+ if ( Init.instance().isTransactionManagementEnabled() )
+ {
+ PhaseId phaseId = event.getPhaseId();
+ boolean commitTran = phaseId == PhaseId.INVOKE_APPLICATION ||
+ event.getFacesContext().getRenderResponse() || //TODO: no need to commit
the tx if we failed to restore the view
+ event.getFacesContext().getResponseComplete() ||
+ phaseId == PhaseId.RENDER_RESPONSE;
+ //( phaseId == PhaseId.RENDER_RESPONSE &&
!Init.instance().isClientSideConversations() );
+
+ if (commitTran)
+ {
+ commitOrRollback(phaseId); //we commit before destroying contexts, cos the
contexts have the PC in them
+ }
+ }
+ }
+
+ protected void handleTransactionsAfterPageActions(FacesContext facesContext)
+ {
+ if ( Init.instance().isTransactionManagementEnabled() )
+ {
+ commitOrRollback(PhaseId.INVOKE_APPLICATION);
+ if ( !facesContext.getResponseComplete() )
+ {
+ begin(PhaseId.INVOKE_APPLICATION);
+ }
+ }
+ }
+
+ protected void afterInvokeApplication()
+ {
+ if ( Init.instance().isTransactionManagementEnabled() )
+ {
+ addTransactionFailedMessage();
+ }
+ }
+
+ protected void afterProcessValidations(FacesContext facesContext)
+ {
+ Validation.instance().afterProcessValidations(facesContext);
+ }
+
+ /**
+ * Set up the Seam contexts, except for the conversation
+ * context
+ */
+ protected void beforeRestoreView(FacesContext facesContext)
+ {
+ FacesLifecycle.beginRequest( facesContext.getExternalContext() );
+ }
+
+ /**
+ * Restore the page and conversation contexts during a JSF request
+ */
+ protected void afterRestoreView(FacesContext facesContext)
+ {
+ FacesLifecycle.resumePage();
+ Map parameters = facesContext.getExternalContext().getRequestParameterMap();
+ ConversationPropagation.instance().restoreConversationId(parameters);
+ boolean conversationFound = Manager.instance().restoreConversation();
+ FacesLifecycle.resumeConversation( facesContext.getExternalContext() );
+ postRestorePage(facesContext, parameters, conversationFound);
+ }
+
+ public void raiseEventsBeforePhase(PhaseEvent event)
+ {
+ if ( Contexts.isApplicationContextActive() )
+ {
+ Events.instance().raiseEvent("org.jboss.seam.beforePhase", event);
+ }
+
+ /*if ( Contexts.isConversationContextActive() &&
Init.instance().isJbpmInstalled() && Pageflow.instance().isInProcess() )
+ {
+ String name;
+ PhaseId phaseId = event.getPhaseId();
+ if ( phaseId == PhaseId.PROCESS_VALIDATIONS )
+ {
+ name = "process-validations";
+ }
+ else if ( phaseId == PhaseId.UPDATE_MODEL_VALUES )
+ {
+ name = "update-model-values";
+ }
+ else if ( phaseId == PhaseId.INVOKE_APPLICATION )
+ {
+ name = "invoke-application";
+ }
+ else if ( phaseId == PhaseId.RENDER_RESPONSE )
+ {
+ name = "render-response";
+ }
+ else
+ {
+ return;
+ }
+ Pageflow.instance().processEvents(name);
+ }*/
+ }
+
+ public void raiseEventsAfterPhase(PhaseEvent event)
+ {
+ if ( Contexts.isApplicationContextActive() )
+ {
+ Events.instance().raiseEvent("org.jboss.seam.afterPhase", event);
+ }
+ }
+
+ /**
+ * Add a faces message when Seam-managed transactions fail.
+ */
+ protected void addTransactionFailedMessage()
+ {
+ try
+ {
+ if ( Transaction.instance().isRolledBackOrMarkedRollback() )
+ {
+ FacesMessages.instance().addFromResourceBundleOrDefault(
+ FacesMessage.SEVERITY_WARN,
+ "org.jboss.seam.TransactionFailed",
+ "Transaction failed"
+ );
+ }
+ }
+ catch (Exception e) {} //swallow silently, not important
+ }
+
+ protected void beforeRenderResponse(FacesContext facesContext)
+ {
+
+ if ( Contexts.isPageContextActive() )
+ {
+ Context pageContext = Contexts.getPageContext();
+ //after every time that the view may have changed,
+ //we need to flush the page context, since the
+ //attribute map is being discarder
+ pageContext.flush();
+ //force refresh of the conversation lists (they are kept in PAGE context)
+ pageContext.remove(Seam.getComponentName(Switcher.class));
+ pageContext.remove("org.jboss.seam.core.conversationList");
+ pageContext.remove("org.jboss.seam.core.conversationStack");
+ }
+
+ preRenderPage(facesContext, PhaseId.RENDER_RESPONSE);
+
+ if ( facesContext.getResponseComplete() )
+ {
+ //workaround for a bug in MyFaces prior to 1.1.3
+ if ( Init.instance().isMyFacesLifecycleBug() )
+ {
+ FacesLifecycle.endRequest( facesContext.getExternalContext() );
+ }
+ }
+ else //if the page actions did not call responseComplete()
+ {
+ FacesMessages.instance().beforeRenderResponse();
+ //do this both before and after render, since conversations
+ //and pageflows can begin during render
+ FacesManager.instance().prepareBackswitch(facesContext);
+ }
+
+ FacesPage.instance().storeConversation();
+ FacesPage.instance().storePageflow();
+
+ PersistenceContexts persistenceContexts = PersistenceContexts.instance();
+ if (persistenceContexts != null)
+ {
+ persistenceContexts.beforeRender();
+ }
+ }
+
+ protected void afterRenderResponse(FacesContext facesContext)
+ {
+ //do this both before and after render, since conversations
+ //and pageflows can begin during render
+ FacesManager.instance().prepareBackswitch(facesContext);
+
+ PersistenceContexts persistenceContexts = PersistenceContexts.instance();
+ if (persistenceContexts != null)
+ {
+ persistenceContexts.afterRender();
+ }
+
+ ExternalContext externalContext = facesContext.getExternalContext();
+ Manager.instance().endRequest( externalContext.getSessionMap() );
+ FacesLifecycle.endRequest(externalContext);
+ }
+
+ protected void afterResponseComplete(FacesContext facesContext)
+ {
+ //responseComplete() was called by one of the other phases,
+ //so we will never get to the RENDER_RESPONSE phase
+ //Note: we can't call Manager.instance().beforeRedirect() here,
+ //since a redirect is not the only reason for a responseComplete
+ ExternalContext externalContext = facesContext.getExternalContext();
+ Manager.instance().endRequest( externalContext.getSessionMap() );
+ FacesLifecycle.endRequest( facesContext.getExternalContext() );
+ }
+
+ private void postRestorePage(FacesContext facesContext, Map parameters, boolean
conversationFound)
+ {
+ if ( !Pages.isDebugPage() )
+ {
+ // Only redirect to no-conversation-view if a login redirect isn't required
+ if (!conversationFound &&
!Pages.instance().isLoginRedirectRequired(facesContext))
+ {
+ Pages.instance().redirectToNoConversationView();
+ }
+
+ Manager.instance().handleConversationPropagation(parameters);
+
+ if ( Init.instance().isJbpmInstalled() && !isExceptionHandlerRedirect()
)
+ {
+ Pageflow.instance().validatePageflow(facesContext);
+ }
+
+ Pages.instance().postRestore(facesContext);
+ }
+ }
+
+
+
+ private boolean preRenderPage(FacesContext facesContext, PhaseId phaseId)
+ {
+ if ( Pages.isDebugPage() )
+ {
+ return false;
+ }
+ else
+ {
+ FacesLifecycle.setPhaseId(PhaseId.INVOKE_APPLICATION);
+ boolean actionsWereCalled = false;
+ try
+ {
+ actionsWereCalled = Pages.instance().preRender(facesContext);
+ return actionsWereCalled;
+ }
+ finally
+ {
+ FacesLifecycle.setPhaseId(phaseId);
+ if (actionsWereCalled)
+ {
+ FacesMessages.afterPhase();
+ handleTransactionsAfterPageActions(facesContext); //TODO: does it really
belong in the finally?
+ }
+ }
+ }
+ }
+
+ private boolean isExceptionHandlerRedirect()
+ {
+ return
Contexts.getConversationContext().isSet("org.jboss.seam.handledException");
+ }
+
+ void begin(PhaseId phaseId)
+ {
+ try
+ {
+ if ( !Transaction.instance().isActiveOrMarkedRollback() )
+ {
+ if(!Transaction.instance().isNoTransaction()){
+ Transaction.instance().rollback();
+ }
+ log.debug("beginning transaction prior to phase: " + phaseId);
+ Transaction.instance().begin();
+ }
+ }
+ catch (Exception e)
+ {
+ throw new IllegalStateException("Could not start transaction", e);
+ }
+ }
+
+ void commitOrRollback(PhaseId phaseId)
+ {
+ try
+ {
+ if ( Transaction.instance().isActive() )
+ {
+ log.debug("committing transaction after phase: " + phaseId);
+ Transaction.instance().commit();
+ }
+ else if ( Transaction.instance().isRolledBackOrMarkedRollback() )
+ {
+ log.debug("rolling back transaction after phase: " + phaseId);
+ Transaction.instance().rollback();
+ }
+ }
+ catch (Exception e)
+ {
+ throw new IllegalStateException("Could not commit transaction", e);
+ }
+ }
+
+}
Property changes on:
trunk/samples/seamPortletEar/seamBookingPortlet/src/main/java/org/ajax4jsf/portlet/seam/SeamPhaseListener.java
___________________________________________________________________
Name: svn:executable
+ *
Name: svn:mime-type
+ text/plain
Name: svn:keywords
+ Date Revision Author