Package io.jmix.ui.screen
Class MasterDetailScreen.BeforeCommitChangesEvent
java.lang.Object
java.util.EventObject
io.jmix.ui.screen.MasterDetailScreen.BeforeCommitChangesEvent
- All Implemented Interfaces:
Serializable
- Enclosing class:
- MasterDetailScreen<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:
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();
}
}
-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected booleanprotected OperationResultprotected final RunnableFields inherited from class java.util.EventObject
source -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionbooleanvoidPrevents commit of the editor form.voidpreventCommit(OperationResult commitResult) Prevents commit of the editor form.voidresume()Resume standard execution.voidresume(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:
getSourcein classEventObject
-
getDataContext
- Returns:
- data context of the screen
-
preventCommit
public void preventCommit()Prevents commit of the editor form. -
preventCommit
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
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
-