From 86134ca56fbc22a189846656c181bbd5144d1113 Mon Sep 17 00:00:00 2001 From: Gavin Cornwell Date: Tue, 2 May 2006 11:27:17 +0000 Subject: [PATCH] Added check for duplicate form submissions to dialog/wizard framework git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/HEAD/root@2736 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261 --- .../web/bean/dialog/BaseDialogBean.java | 57 +++++++++++-------- .../web/bean/wizard/BaseWizardBean.java | 2 - 2 files changed, 34 insertions(+), 25 deletions(-) diff --git a/source/java/org/alfresco/web/bean/dialog/BaseDialogBean.java b/source/java/org/alfresco/web/bean/dialog/BaseDialogBean.java index e3de0e8814..a3f1fcbb27 100644 --- a/source/java/org/alfresco/web/bean/dialog/BaseDialogBean.java +++ b/source/java/org/alfresco/web/bean/dialog/BaseDialogBean.java @@ -23,6 +23,8 @@ import org.alfresco.web.ui.common.Utils; */ public abstract class BaseDialogBean implements IDialogBean { + protected boolean isFinished = false; + // services common to most dialogs protected BrowseBean browseBean; protected NavigationBean navigator; @@ -34,6 +36,9 @@ public abstract class BaseDialogBean implements IDialogBean { // tell any beans to update themselves so the UI gets refreshed UIContextService.getInstance(FacesContext.getCurrentInstance()).notifyBeans(); + + // reset the isFinished flag + this.isFinished = false; } public String cancel() @@ -45,30 +50,36 @@ public abstract class BaseDialogBean implements IDialogBean { String outcome = getDefaultFinishOutcome(); - UserTransaction tx = null; - - try + // check the isFinished flag to stop the finish button + // being pressed multiple times + if (this.isFinished == false) { - FacesContext context = FacesContext.getCurrentInstance(); - tx = Repository.getUserTransaction(context); - tx.begin(); - - // call the actual implementation - outcome = finishImpl(context, outcome); - - // persist the changes - tx.commit(); - - // allow any subclasses to perform post commit processing - // i.e. resetting state or setting status messages - outcome = doPostCommitProcessing(context, outcome); - } - catch (Throwable e) - { - // rollback the transaction - try { if (tx != null) {tx.rollback();} } catch (Exception ex) {} - Utils.addErrorMessage(formatErrorMessage(e)); - outcome = null; + this.isFinished = true; + UserTransaction tx = null; + + try + { + FacesContext context = FacesContext.getCurrentInstance(); + tx = Repository.getUserTransaction(context); + tx.begin(); + + // call the actual implementation + outcome = finishImpl(context, outcome); + + // persist the changes + tx.commit(); + + // allow any subclasses to perform post commit processing + // i.e. resetting state or setting status messages + outcome = doPostCommitProcessing(context, outcome); + } + catch (Throwable e) + { + // rollback the transaction + try { if (tx != null) {tx.rollback();} } catch (Exception ex) {} + Utils.addErrorMessage(formatErrorMessage(e)); + outcome = null; + } } return outcome; diff --git a/source/java/org/alfresco/web/bean/wizard/BaseWizardBean.java b/source/java/org/alfresco/web/bean/wizard/BaseWizardBean.java index 5b74b6bdf3..4ed69c1065 100644 --- a/source/java/org/alfresco/web/bean/wizard/BaseWizardBean.java +++ b/source/java/org/alfresco/web/bean/wizard/BaseWizardBean.java @@ -2,8 +2,6 @@ package org.alfresco.web.bean.wizard; import javax.faces.context.FacesContext; -import org.alfresco.service.cmr.model.FileFolderService; -import org.alfresco.service.cmr.search.SearchService; import org.alfresco.web.app.AlfrescoNavigationHandler; import org.alfresco.web.app.Application; import org.alfresco.web.bean.dialog.BaseDialogBean;