diff --git a/source/java/org/alfresco/web/bean/dialog/BaseDialogBean.java b/source/java/org/alfresco/web/bean/dialog/BaseDialogBean.java index eeef78b4c9..c61d2db421 100644 --- a/source/java/org/alfresco/web/bean/dialog/BaseDialogBean.java +++ b/source/java/org/alfresco/web/bean/dialog/BaseDialogBean.java @@ -47,6 +47,7 @@ import org.alfresco.web.bean.BrowseBean; import org.alfresco.web.bean.NavigationBean; import org.alfresco.web.bean.repository.Repository; import org.alfresco.web.config.DialogsConfigElement.DialogButtonConfig; +import org.alfresco.web.ui.common.ReportedException; import org.alfresco.web.ui.common.Utils; /** @@ -124,7 +125,7 @@ public abstract class BaseDialogBean implements IDialogBean, Serializable try { // Execute - outcome = txnHelper.doInTransaction(callback); + outcome = txnHelper.doInTransaction(callback, false, true); // allow any subclasses to perform post commit processing // i.e. resetting state or setting status messages @@ -138,9 +139,11 @@ public abstract class BaseDialogBean implements IDialogBean, Serializable { // reset the flag so we can re-attempt the operation isFinished = false; - - Utils.addErrorMessage(formatErrorMessage(e), e); outcome = getErrorOutcome(e); + if (e instanceof ReportedException == false) + { + Utils.addErrorMessage(formatErrorMessage(e), e); + } ReportedException.throwIfNecessary(e); } } @@ -353,7 +356,7 @@ public abstract class BaseDialogBean implements IDialogBean, Serializable * @return The outcome */ protected abstract String finishImpl(FacesContext context, String outcome) - throws Exception; + throws Throwable; /** * Performs any post commit processing subclasses may want to provide diff --git a/source/java/org/alfresco/web/ui/common/ReportedException.java b/source/java/org/alfresco/web/ui/common/ReportedException.java new file mode 100644 index 0000000000..8fb1488f5a --- /dev/null +++ b/source/java/org/alfresco/web/ui/common/ReportedException.java @@ -0,0 +1,42 @@ +/* + * Copyright (C) 2005-2009 Alfresco Software Limited. + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + + * As a special exception to the terms and conditions of version 2.0 of + * the GPL, you may redistribute this Program in connection with Free/Libre + * and Open Source Software ("FLOSS") applications as described in Alfresco's + * FLOSS exception. You should have recieved a copy of the text describing + * the FLOSS exception, and it is also available here: + * http://www.alfresco.com/legal/licensing" + */ +package org.alfresco.web.ui.common; + +/** + * Unchecked exception wrapping an already-reported exception. The dialog code can use this to + * detect whether or not to report further to the user. + * + * @author Derek Hulley + * @since 3.1 + */ +public class ReportedException extends RuntimeException +{ + private static final long serialVersionUID = -4179045854462002741L; + + public ReportedException(Throwable e) + { + super(e); + } +} diff --git a/source/java/org/alfresco/web/ui/common/Utils.java b/source/java/org/alfresco/web/ui/common/Utils.java index 908ad5b627..04ad5a6b5c 100644 --- a/source/java/org/alfresco/web/ui/common/Utils.java +++ b/source/java/org/alfresco/web/ui/common/Utils.java @@ -44,6 +44,7 @@ import javax.faces.el.EvaluationException; import javax.faces.el.MethodBinding; import javax.faces.event.AbortProcessingException; import javax.faces.event.ActionEvent; +import javax.transaction.UserTransaction; import org.alfresco.config.ConfigElement; import org.alfresco.error.AlfrescoRuntimeException; @@ -56,6 +57,7 @@ import org.alfresco.jlan.server.filesys.FilesystemsConfigSection; import org.alfresco.model.ApplicationModel; import org.alfresco.model.ContentModel; import org.alfresco.repo.security.permissions.AccessDeniedException; +import org.alfresco.repo.transaction.RetryingTransactionHelper; import org.alfresco.repo.webdav.WebDAVServlet; import org.alfresco.service.cmr.dictionary.DictionaryService; import org.alfresco.service.cmr.model.FileFolderService; @@ -814,6 +816,20 @@ public final class Utils extends StringUtils */ public static void addErrorMessage(String msg, Throwable err) { + UserTransaction txn = RetryingTransactionHelper.getActiveUserTransaction(); + if (txn != null) + { + // We're in a transaction and need to ensure that we ONLY rollback + try + { + txn.setRollbackOnly(); + } + catch (Throwable e) + { + // Ignore + } + } + FacesContext context = FacesContext.getCurrentInstance( ); FacesMessage facesMsg = new FacesMessage(FacesMessage.SEVERITY_ERROR, msg, msg); context.addMessage(null, facesMsg);