Package io.jmix.ui.screen
Class StandardEditor.BeforeCommitChangesEvent
java.lang.Object
java.util.EventObject
io.jmix.ui.screen.StandardEditor.BeforeCommitChangesEvent
- All Implemented Interfaces:
Serializable
- Enclosing class:
- StandardEditor<T>
Event sent before commit of data context from
Use this event listener to prevent commit and/or show additional dialogs to user before commit, for example:
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(); } }
-
Field Summary
Modifier and TypeFieldDescriptionprotected boolean
protected OperationResult
protected final Runnable
Fields inherited from class java.util.EventObject
source
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionboolean
void
Prevents commit of the screen.void
preventCommit
(OperationResult commitResult) Prevents commit of the screen.void
resume()
Resume standard execution.void
resume
(OperationResult result) Resume with the passed result ignoring standard execution.Methods inherited from class java.util.EventObject
toString
-
Field Details
-
resumeAction
-
commitPrevented
protected boolean commitPrevented -
commitResult
-
-
Constructor Details
-
BeforeCommitChangesEvent
-
-
Method Details
-
getSource
- Overrides:
getSource
in classEventObject
-
getDataContext
- Returns:
- data context of the screen
-
preventCommit
public void preventCommit()Prevents commit of the screen. -
preventCommit
Prevents commit of the screen.- Parameters:
commitResult
- result object that will be returned from theStandardEditor.commitChanges()
} method
-
resume
public void resume()Resume standard execution. -
resume
Resume with the passed result ignoring standard execution. The standard commit will not be performed. -
getCommitResult
- Returns:
- result passed to the
preventCommit(OperationResult)
method
-
isCommitPrevented
public boolean isCommitPrevented()- Returns:
- whether the commit was prevented by invoking
preventCommit()
method
-