Class StandardEditor.BeforeCommitChangesEvent

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

public static class StandardEditor.BeforeCommitChangesEvent extends EventObject
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

    • 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 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

      @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