Class MasterDetailScreen.BeforeCommitChangesEvent

java.lang.Object
java.util.EventObject
io.jmix.ui.screen.MasterDetailScreen.BeforeCommitChangesEvent
All Implemented Interfaces:
Serializable
Enclosing class:
MasterDetailScreen<T>

public static class MasterDetailScreen.BeforeCommitChangesEvent extends EventObject
Event sent before commit of data context from MasterDetailScreen.commitEditorChanges() 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(commitEditorChanges());
                             }),
                             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, Runnable resumeAction)
  • Method Details

    • getSource

      public Screen getSource()
      Overrides:
      getSource in class EventObject
    • getDataContext

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

      public void preventCommit()
      Prevents commit of the editor form.
    • preventCommit

      public void preventCommit(OperationResult commitResult)
      Prevents commit of the editor form.
      Parameters:
      commitResult - result object that will be used to resume entity saving
    • 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

      @Nullable public OperationResult getCommitResult()
      Returns:
      result passed to the preventCommit(OperationResult) method
    • isCommitPrevented

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