Class StandardDetailView.BeforeSaveEvent

java.lang.Object
java.util.EventObject
com.vaadin.flow.component.ComponentEvent<View<?>>
io.jmix.flowui.view.StandardDetailView.BeforeSaveEvent
All Implemented Interfaces:
Serializable
Enclosing class:
StandardDetailView<T>

public static class StandardDetailView.BeforeSaveEvent extends com.vaadin.flow.component.ComponentEvent<View<?>>
Event sent before saving the view data context.
Use this event listener to prevent saving and/or interact with the user before save, for example:
     @Subscribe
     protected void onBeforeSave(BeforeSaveEvent event) {
         if (getEditedEntity().getDescription() == null) {
             notifications.show("Description required");
             event.preventSave();
         }
     }
 

Show dialog and resume saving after:

     @Subscribe
     protected void onBeforeSave(BeforeSaveEvent event) {
         if (getEditedEntity().getDescription() == null) {
             dialogs.createOptionDialog()
                     .withHeader("Question")
                     .withText("Do you want to set default description?")
                     .withActions(
                             new DialogAction(DialogAction.Type.YES).withHandler(e -> {
                                 getEditedEntity().setDescription("No description");

                                 // retry save and resume action
                                 event.resume(save());
                             }),
                             new DialogAction(DialogAction.Type.NO).withHandler(e -> {
                                 // trigger standard save and resume action
                                 event.resume();
                             })
                     )
                     .open();

             event.preventSave();
         }
     }
 
See Also:
  • Field Details

    • resumeAction

      protected final Runnable resumeAction
    • savePrevented

      protected boolean savePrevented
    • saveResult

      protected OperationResult saveResult
  • Constructor Details

    • BeforeSaveEvent

      public BeforeSaveEvent(View<?> source, @Nullable Runnable resumeAction)
  • Method Details

    • getDataContext

      public DataContext getDataContext()
      Returns:
      data context of the view
    • preventSave

      public void preventSave()
      Prevents saving of the view data.
    • preventSave

      public void preventSave(OperationResult saveResult)
      Prevents saving of the view data.
      Parameters:
      saveResult - result object that will be returned from the StandardDetailView.saveChanges()} method
    • resume

      public void resume()
      Resume standard execution.
    • resume

      public void resume(OperationResult result)
      Resume with the passed result ignoring standard execution. The standard save will not be performed.
    • getSaveResult

      public Optional<OperationResult> getSaveResult()
      Returns:
      result passed to the preventSave(OperationResult) method
    • isSavePrevented

      public boolean isSavePrevented()
      Returns:
      whether the saving process was prevented by invoking preventSave() method