Class StandardEditor.BeforeCommitChangesEvent

java.lang.Object
java.util.EventObject
com.vaadin.flow.component.ComponentEvent<Screen<?>>
io.jmix.flowui.screen.StandardEditor.BeforeCommitChangesEvent
All Implemented Interfaces:
Serializable
Enclosing class:
StandardEditor<T>

public static class StandardEditor.BeforeCommitChangesEvent extends com.vaadin.flow.component.ComponentEvent<Screen<?>>
Event sent before commit of data context from StandardEditor.commitChanges() call.
Use this event listener to prevent commit and/or show additional dialogs to user before commit, for example:
     @Subscribe
     protected void onBeforeCommit(BeforeCommitChangesEvent event) {
         if (getEditedEntity().getDescription() == null) {
             notifications.create().withCaption("Description required").show();
             event.preventCommit();
         }
     }
 

Show dialog and resume commit after:

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

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

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

    • resumeAction

      protected final Runnable resumeAction
    • commitPrevented

      protected boolean commitPrevented
    • commitResult

      protected OperationResult commitResult
  • Constructor Details

    • BeforeCommitChangesEvent

      public BeforeCommitChangesEvent(Screen<?> source, @Nullable Runnable resumeAction)
  • Method Details

    • getDataContext

      public DataContext getDataContext()
      Returns:
      data context of the screen
    • preventCommit

      public void preventCommit()
      Prevents commit of the screen.
    • preventCommit

      public void preventCommit(OperationResult commitResult)
      Prevents commit of the screen.
      Parameters:
      commitResult - result object that will be returned from the StandardEditor.commitChanges()} method
    • resume

      public void resume()
      Resume standard execution.
    • resume

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

      public Optional<OperationResult> getCommitResult()
      Returns:
      result passed to the preventCommit(OperationResult) method
    • isCommitPrevented

      public boolean isCommitPrevented()
      Returns:
      whether the commit was prevented by invoking preventCommit() method