Ticket T291151
Visible to All Users

How do I set the Action's confirmation message dynamically based on object property values before this action gets executed?

created 9 years ago (modified 9 years ago)

Hi,

I need to set confirmation message dynamically before customer click the Save action. There is a boolean property "State". I need to show confirmation message if this property set to false otherwise confirmation message must be set to null. I tried many ways but failed. For example I used ObjectSpace object_change event but checking every changed obejct is not an effective way. How can I achive this goal ?

Answers approved by DevExpress Support

created 9 years ago (modified 8 years ago)

Hello,

The idea is to implement a custom ViewController to access a required Action as per Customize Controllers and Actions  and modify its ConfirmationMessage property in code on required events (e.g. Controller.Activated, View.ControlsCreated, View.CurrentObjectChanged,  CRUD events of IObjectSpace or even the 'Changed' event of the current persistent object) based on the current object value.
I have modified your code as follows:

C#
using DevExpress.ExpressApp; using DevExpress.ExpressApp.SystemModule; using Solution1.Module.BusinessObjects; namespace YourSolutionName.Module.Controllers { public class UpdateConfirmationMessageForProjectDetailViewController : ObjectViewController<DetailView, Project> { private ModificationsController controller; protected override void OnActivated() { base.OnActivated(); // Perform various tasks depending on the target View. controller = Frame.GetController<ModificationsController>(); SetConfirmationMessage(ViewCurrentObject); View.ObjectSpace.ObjectChanged += ObjectSpace_ObjectChanged; } void ObjectSpace_ObjectChanged(object sender, ObjectChangedEventArgs e) { if (e.Object is Project) { SetConfirmationMessage((Project)e.Object); } } protected override void OnDeactivated() { // Unsubscribe from previously subscribed events and release other references and resources. View.ObjectSpace.ObjectChanged -= ObjectSpace_ObjectChanged; base.OnDeactivated(); } private void SetConfirmationMessage(Project theProject) { bool yourBusinessCondition = theProject != null && !theProject.State; string message = yourBusinessCondition ? string.Format("{0} project state is false. Do you want to start this project?", theProject.Name) : null; if (controller != null) { controller.SaveAndCloseAction.ConfirmationMessage = message; controller.SaveAction.ConfirmationMessage = message; controller.SaveAndNewAction.ConfirmationMessage = message; } } } }

Another example is available in the end of the How to: Access Objects Selected in the Current View help topic, where the DeleteObjectsViewController.DeleteAction's confirmation message is updated based on the Full Name of the Contact that is going to be deleted.

Please let me know if this solution meets your needs. I wanted to emphasize that handling the ObjectChanged event in this manner should not cause any problems.

Important notes:

  1. Decorate your dependent business class property with the ImmediatePostDataattribute to be notified of object changes immediately.
  2. In WinForms to display a confirmation message after executing a custom operation in code of your Controller, use the XafApplication.AskConfirmation or WinApplication.GetUserChoice method. To get an application's instance in the Controller, use its Application property.
  3. At the moment XAF doesn't allow you to set unique confirmation message for each ChoiceActionItem of SingleChoiceAction.
    Comments (3)
    YS YS
    YALIN SOFTWARE 9 years ago

      It does not work correctly. I set State as false and saved. After that I set State true and clicked to Save action but I got confirmation message (which is wrong). So  when State is changed I need to set confirmation message  without to Save it.

      Dennis Garavsky (DevExpress) 9 years ago

        This code operates correctly in my tests. Please verify that the ImmediatePostData attribute is set for your State property to be notified of object changes immediately.

        YS YS
        YALIN SOFTWARE 9 years ago

          Sorry, I forget to set ImmediatePostData. Now It works. Thank you, Dennis

          Disclaimer: The information provided on DevExpress.com and affiliated web properties (including the DevExpress Support Center) is provided "as is" without warranty of any kind. Developer Express Inc disclaims all warranties, either express or implied, including the warranties of merchantability and fitness for a particular purpose. Please refer to the DevExpress.com Website Terms of Use for more information in this regard.

          Confidential Information: Developer Express Inc does not wish to receive, will not act to procure, nor will it solicit, confidential or proprietary materials and information from you through the DevExpress Support Center or its web properties. Any and all materials or information divulged during chats, email communications, online discussions, Support Center tickets, or made available to Developer Express Inc in any manner will be deemed NOT to be confidential by Developer Express Inc. Please refer to the DevExpress.com Website Terms of Use for more information in this regard.