[seam-commits] Seam SVN: r10272 - in trunk/src/main/org/jboss/seam: transaction and 1 other directory.
seam-commits at lists.jboss.org
seam-commits at lists.jboss.org
Thu Apr 2 02:10:18 EDT 2009
Author: dan.j.allen
Date: 2009-04-02 02:10:18 -0400 (Thu, 02 Apr 2009)
New Revision: 10272
Added:
trunk/src/main/org/jboss/seam/transaction/FacesTransactionEvents.java
Modified:
trunk/src/main/org/jboss/seam/jsf/SeamPhaseListener.java
trunk/src/main/org/jboss/seam/transaction/Transaction.java
Log:
JBSEAM-3116
Modified: trunk/src/main/org/jboss/seam/jsf/SeamPhaseListener.java
===================================================================
--- trunk/src/main/org/jboss/seam/jsf/SeamPhaseListener.java 2009-04-02 05:27:41 UTC (rev 10271)
+++ trunk/src/main/org/jboss/seam/jsf/SeamPhaseListener.java 2009-04-02 06:10:18 UTC (rev 10272)
@@ -11,6 +11,7 @@
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 static org.jboss.seam.transaction.Transaction.TRANSACTION_FAILED;
import java.lang.reflect.Method;
import java.util.Map;
@@ -43,6 +44,7 @@
import org.jboss.seam.pageflow.Pageflow;
import org.jboss.seam.persistence.PersistenceContexts;
import org.jboss.seam.transaction.Transaction;
+import org.jboss.seam.transaction.UserTransaction;
import org.jboss.seam.util.Reflections;
import org.jboss.seam.web.ServletContexts;
@@ -361,7 +363,7 @@
{
if ( Init.instance().isTransactionManagementEnabled() )
{
- addTransactionFailedMessage();
+ raiseTransactionFailedEvent();
}
}
@@ -436,19 +438,16 @@
}
/**
- * Add a faces message when Seam-managed transactions fail.
+ * Raise an event so that an observer may add a faces message when Seam-managed transactions fail.
*/
- protected void addTransactionFailedMessage()
+ protected void raiseTransactionFailedEvent()
{
try
{
- if ( Transaction.instance().isRolledBackOrMarkedRollback() )
+ UserTransaction tx = Transaction.instance();
+ if ( tx.isRolledBackOrMarkedRollback() )
{
- FacesMessages.instance().addFromResourceBundleOrDefault(
- StatusMessage.Severity.WARN,
- "org.jboss.seam.TransactionFailed",
- "Transaction failed"
- );
+ if (Events.exists()) Events.instance().raiseEvent(TRANSACTION_FAILED, tx.getStatus());
}
}
catch (Exception e) {} //swallow silently, not important
Added: trunk/src/main/org/jboss/seam/transaction/FacesTransactionEvents.java
===================================================================
--- trunk/src/main/org/jboss/seam/transaction/FacesTransactionEvents.java (rev 0)
+++ trunk/src/main/org/jboss/seam/transaction/FacesTransactionEvents.java 2009-04-02 06:10:18 UTC (rev 10272)
@@ -0,0 +1,66 @@
+package org.jboss.seam.transaction;
+
+import static org.jboss.seam.ScopeType.APPLICATION;
+import static org.jboss.seam.annotations.Install.BUILT_IN;
+
+import org.jboss.seam.annotations.Install;
+import org.jboss.seam.annotations.Name;
+import org.jboss.seam.annotations.Observer;
+import org.jboss.seam.annotations.Scope;
+import org.jboss.seam.annotations.Startup;
+import org.jboss.seam.annotations.intercept.BypassInterceptors;
+import org.jboss.seam.international.StatusMessages;
+import org.jboss.seam.international.StatusMessage.Severity;
+
+/**
+ * Produces StatusMessages for JSF in response of certain transaction events.
+ * These events can be observed by support classes for other UI frameworks
+ * to produce similar messages.
+ *
+ * @author Dan Allen
+ */
+ at Name("org.jboss.seam.transaction.facesTransactionEvents")
+ at Scope(APPLICATION)
+ at Install(precedence = BUILT_IN, classDependencies = "javax.faces.context.FacesContext")
+ at BypassInterceptors
+ at Startup
+public class FacesTransactionEvents
+{
+ private boolean transactionFailedMessageEnabled = true;
+
+ @Observer(Transaction.TRANSACTION_FAILED)
+ public void addTransactionFailedMessage(int status)
+ {
+ if (transactionFailedMessageEnabled) {
+ StatusMessages.instance().addFromResourceBundleOrDefault(
+ getTransactionFailedMessageSeverity(),
+ getTransactionFailedMessageKey(),
+ getTransactionFailedMessage());
+ }
+ }
+
+ public String getTransactionFailedMessage()
+ {
+ return "Transaction failed";
+ }
+
+ public Severity getTransactionFailedMessageSeverity()
+ {
+ return Severity.WARN;
+ }
+
+ public String getTransactionFailedMessageKey()
+ {
+ return "org.jboss.seam.TransactionFailed";
+ }
+
+ public boolean isTransactionFailedMessageEnabled()
+ {
+ return transactionFailedMessageEnabled;
+ }
+
+ public void setTransactionFailedMessageEnabled(boolean enabled)
+ {
+ this.transactionFailedMessageEnabled = enabled;
+ }
+}
Modified: trunk/src/main/org/jboss/seam/transaction/Transaction.java
===================================================================
--- trunk/src/main/org/jboss/seam/transaction/Transaction.java 2009-04-02 05:27:41 UTC (rev 10271)
+++ trunk/src/main/org/jboss/seam/transaction/Transaction.java 2009-04-02 06:10:18 UTC (rev 10272)
@@ -31,6 +31,9 @@
@BypassInterceptors
public class Transaction
{
+ // Event keys
+ public static final String TRANSACTION_FAILED = "org.jboss.seam.transaction.transactionFailed";
+
public static UserTransaction instance()
{
return (UserTransaction) Component.getInstance(Transaction.class, ScopeType.EVENT);
More information about the seam-commits
mailing list