diff --git a/source/java/org/alfresco/web/bean/actions/BaseActionWizard.java b/source/java/org/alfresco/web/bean/actions/BaseActionWizard.java index 8814cb6411..0fbdc81348 100644 --- a/source/java/org/alfresco/web/bean/actions/BaseActionWizard.java +++ b/source/java/org/alfresco/web/bean/actions/BaseActionWizard.java @@ -18,11 +18,10 @@ */ package org.alfresco.web.bean.actions; -import java.io.IOException; -import java.io.ObjectInputStream; import java.io.Serializable; import java.text.MessageFormat; import java.util.ArrayList; +import java.util.Collections; import java.util.HashMap; import java.util.List; import java.util.Map; @@ -35,9 +34,6 @@ import javax.faces.model.DataModel; import javax.faces.model.ListDataModel; import javax.faces.model.SelectItem; -import org.springframework.extensions.config.Config; -import org.springframework.extensions.config.ConfigElement; -import org.springframework.extensions.config.ConfigService; import org.alfresco.error.AlfrescoRuntimeException; import org.alfresco.model.ContentModel; import org.alfresco.service.cmr.action.ActionDefinition; @@ -63,6 +59,9 @@ import org.alfresco.web.ui.common.Utils; import org.alfresco.web.ui.common.component.UIGenericPicker; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; +import org.springframework.extensions.config.Config; +import org.springframework.extensions.config.ConfigElement; +import org.springframework.extensions.config.ConfigService; /** * Base class for the "Run Action" and "Create Rule" wizards. @@ -73,6 +72,7 @@ public abstract class BaseActionWizard extends BaseWizardBean { protected static final String PROP_ACTION_NAME = "actionName"; protected static final String PROP_ACTION_SUMMARY = "actionSummary"; + protected static final String PROP_ACTION_EMAIL_RECIPIENTS= "actionEmailRecipients"; protected static final String NO_PARAMS_MARKER = "noParamsMarker"; protected static final String ERROR_ACTION_CANNOT_BE_EXECUTE_REPEATEDLY = "action_cannot_be_execute_repeatedly"; @@ -91,10 +91,8 @@ public abstract class BaseActionWizard extends BaseWizardBean protected List users; protected List encodings; protected List objectTypes; - protected List emailRecipients; - transient protected DataModel allActionsDataModel; - transient protected DataModel emailRecipientsDataModel; + transient protected DataModel currentEmailRecipientsDataModel; protected boolean editingAction; protected String action; @@ -119,13 +117,14 @@ public abstract class BaseActionWizard extends BaseWizardBean this.action = null; this.users = null; this.actions = null; - this.emailRecipientsDataModel = null; + this.currentEmailRecipientsDataModel = null; this.usingTemplate = null; - this.emailRecipients = new ArrayList(4); this.allActionsProperties = new ArrayList>(); this.currentActionProperties = new HashMap(3); + this.editingAction = false; + initialiseActionHandlers(); } @@ -188,14 +187,14 @@ public abstract class BaseActionWizard extends BaseWizardBean */ public DataModel getEmailRecipientsDataModel() { - if (this.emailRecipientsDataModel == null) + if (this.currentEmailRecipientsDataModel == null) { - this.emailRecipientsDataModel = new ListDataModel(); + this.currentEmailRecipientsDataModel = new ListDataModel(); } + + this.currentEmailRecipientsDataModel.setWrappedData(getEmailRecipients(this.currentActionProperties)); - this.emailRecipientsDataModel.setWrappedData(this.emailRecipients); - - return this.emailRecipientsDataModel; + return this.currentEmailRecipientsDataModel; } /** @@ -590,9 +589,15 @@ public abstract class BaseActionWizard extends BaseWizardBean * * @return List of email recipients */ - public List getEmailRecipients() + public List getEmailRecipients(Map actionProperties) { - return this.emailRecipients; + List currentEmailRecipients = (List) actionProperties.get(PROP_ACTION_EMAIL_RECIPIENTS); + if (currentEmailRecipients == null) + { + currentEmailRecipients = new ArrayList(4); + actionProperties.put(PROP_ACTION_EMAIL_RECIPIENTS, (Serializable)currentEmailRecipients); + } + return currentEmailRecipients; } // ------------------------------------------------------------------------------ @@ -613,6 +618,7 @@ public abstract class BaseActionWizard extends BaseWizardBean HashMap actionProps = new HashMap(3); actionProps.put(PROP_ACTION_NAME, this.action); this.currentActionProperties = actionProps; + this.currentEmailRecipientsDataModel = null; // get the handler for the action, if there isn't one we presume it // is a no-parameter action @@ -660,9 +666,10 @@ public abstract class BaseActionWizard extends BaseWizardBean { // use the built in JSF support for retrieving the object for the // row that was clicked by the user - Map actionToEdit = (Map)this.allActionsDataModel.getRowData(); - this.action = (String)actionToEdit.get(PROP_ACTION_NAME); - this.currentActionProperties = actionToEdit; + int index = this.allActionsDataModel.getRowIndex(); + this.currentActionProperties = this.allActionsProperties.get(index); + this.action = (String)this.currentActionProperties.get(PROP_ACTION_NAME); + this.currentEmailRecipientsDataModel = null; // set the flag to show we are editing an action this.editingAction = true; @@ -713,8 +720,8 @@ public abstract class BaseActionWizard extends BaseWizardBean // use the built in JSF support for retrieving the object for the // row that was clicked by the user @SuppressWarnings("unchecked") - Map actionToRemove = (Map)this.allActionsDataModel.getRowData(); - this.allActionsProperties.remove(actionToRemove); + int index = this.allActionsDataModel.getRowIndex(); + this.allActionsProperties.remove(index); // reset the action drop down this.action = null; @@ -750,13 +757,14 @@ public abstract class BaseActionWizard extends BaseWizardBean String[] results = picker.getSelectedResults(); if (results != null && results.length != 0) { + List currentEmailRecipients = getEmailRecipients(this.currentActionProperties); for (String authority : results) { // first check the authority has not already been added to the list boolean alreadyAdded = false; - for (int i=0; i currentEmailRecipients = getEmailRecipients(this.currentActionProperties); + int index = this.currentEmailRecipientsDataModel.getRowIndex(); + currentEmailRecipients.remove(index); } /** @@ -1065,9 +1074,10 @@ public abstract class BaseActionWizard extends BaseWizardBean public boolean isFinishButtonDisabled() { - if (emailRecipients != null) + List currentEmailRecipients = (List) this.currentActionProperties.get(PROP_ACTION_EMAIL_RECIPIENTS); + if (currentEmailRecipients != null) { - return emailRecipients.isEmpty(); + return currentEmailRecipients.isEmpty(); } return true; } @@ -1136,14 +1146,4 @@ public abstract class BaseActionWizard extends BaseWizardBean private String name; private String authority; } - - private void readObject(ObjectInputStream in) throws IOException, ClassNotFoundException - { - in.defaultReadObject(); - - this.allActionsDataModel = new ListDataModel(); - this.allActionsDataModel.setWrappedData(this.allActionsProperties); - this.emailRecipientsDataModel = new ListDataModel(); - this.emailRecipientsDataModel.setWrappedData(this.emailRecipients); - } } diff --git a/source/java/org/alfresco/web/bean/actions/handlers/MailHandler.java b/source/java/org/alfresco/web/bean/actions/handlers/MailHandler.java index 7be7311387..25386ce25e 100644 --- a/source/java/org/alfresco/web/bean/actions/handlers/MailHandler.java +++ b/source/java/org/alfresco/web/bean/actions/handlers/MailHandler.java @@ -62,10 +62,11 @@ public class MailHandler extends BaseActionHandler getWizardManager().getBean(); // add the person(s) it's going to as a list of authorities - List recipients = new ArrayList(wizard.getEmailRecipients().size()); - for (int i=0; i < wizard.getEmailRecipients().size(); i++) + List wizardRecipients = wizard.getEmailRecipients(actionProps); + List recipients = new ArrayList(wizardRecipients.size()); + for (int i=0; i < wizardRecipients.size(); i++) { - RecipientWrapper wrapper = wizard.getEmailRecipients().get(i); + RecipientWrapper wrapper = wizardRecipients.get(i); recipients.add(wrapper.getAuthority()); } @@ -133,7 +134,7 @@ public void prepareForEdit(Map actionProps, // rebuild the list of RecipientWrapper objects from the stored action for (String authority : recipients) { - wizard.getEmailRecipients().add( + wizard.getEmailRecipients(actionProps).add( new RecipientWrapper(wizard.displayLabelForAuthority(authority), authority)); } @@ -157,13 +158,14 @@ public void prepareForEdit(Map actionProps, if (addresses == null || addresses.length() == 0) { - if (actionWizard.getEmailRecipients().size() != 0) + List wizardRecipients = actionWizard.getEmailRecipients(actionProps); + if (wizardRecipients.size() != 0) { StringBuilder builder = new StringBuilder(); - for (int i=0; i < actionWizard.getEmailRecipients().size(); i++) + for (int i=0; i < wizardRecipients.size(); i++) { - RecipientWrapper wrapper = actionWizard.getEmailRecipients().get(i); + RecipientWrapper wrapper = wizardRecipients.get(i); if (i != 0) { builder.append(", "); diff --git a/source/java/org/alfresco/web/bean/rules/EditRuleWizard.java b/source/java/org/alfresco/web/bean/rules/EditRuleWizard.java index 429acaad88..4f6c2d5018 100644 --- a/source/java/org/alfresco/web/bean/rules/EditRuleWizard.java +++ b/source/java/org/alfresco/web/bean/rules/EditRuleWizard.java @@ -101,6 +101,7 @@ public class EditRuleWizard extends CreateCompositeRuleWizard for (Action action : actions) { this.currentActionProperties = new HashMap(3); + this.currentEmailRecipientsDataModel = null; this.action = action.getActionDefinitionName(); this.currentActionProperties.put(PROP_ACTION_NAME, this.action);