Package io.jmix.flowui.view
Class StandardDetailView.BeforeSaveEvent
java.lang.Object
java.util.EventObject
com.vaadin.flow.component.ComponentEvent<View<?>>
io.jmix.flowui.view.StandardDetailView.BeforeSaveEvent
- All Implemented Interfaces:
Serializable
- Enclosing class:
- StandardDetailView<T>
public static class StandardDetailView.BeforeSaveEvent
extends com.vaadin.flow.component.ComponentEvent<View<?>>
Event sent before saving the view data context.
Use this event listener to prevent saving and/or interact with the user before save, for example:
Use this event listener to prevent saving and/or interact with the user before save, for example:
@Subscribe protected void onBeforeSave(BeforeSaveEvent event) { if (getEditedEntity().getDescription() == null) { notifications.show("Description required"); event.preventSave(); } }
Show dialog and resume saving after:
@Subscribe protected void onBeforeSave(BeforeSaveEvent event) { if (getEditedEntity().getDescription() == null) { dialogs.createOptionDialog() .withHeader("Question") .withText("Do you want to set default description?") .withActions( new DialogAction(DialogAction.Type.YES).withHandler(e -> { getEditedEntity().setDescription("No description"); // retry save and resume action event.resume(save()); }), new DialogAction(DialogAction.Type.NO).withHandler(e -> { // trigger standard save and resume action event.resume(); }) ) .open(); event.preventSave(); } }
-
Field Summary
Modifier and TypeFieldDescriptionprotected final Runnable
protected boolean
protected OperationResult
Fields inherited from class java.util.EventObject
source
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionboolean
void
Prevents saving of the view data.void
preventSave
(OperationResult saveResult) Prevents saving of the view data.void
resume()
Resume standard execution.void
resume
(OperationResult result) Resume with the passed result ignoring standard execution.Methods inherited from class com.vaadin.flow.component.ComponentEvent
getSource, isFromClient, unregisterListener
Methods inherited from class java.util.EventObject
toString
-
Field Details
-
resumeAction
-
savePrevented
protected boolean savePrevented -
saveResult
-
-
Constructor Details
-
BeforeSaveEvent
-
-
Method Details
-
getDataContext
- Returns:
- data context of the view
-
preventSave
public void preventSave()Prevents saving of the view data. -
preventSave
Prevents saving of the view data.- Parameters:
saveResult
- result object that will be returned from theStandardDetailView.saveChanges(boolean)
} method
-
resume
public void resume()Resume standard execution. -
resume
Resume with the passed result ignoring standard execution. The standard save will not be performed. -
getSaveResult
- Returns:
- result passed to the
preventSave(OperationResult)
method
-
isSavePrevented
public boolean isSavePrevented()- Returns:
- whether the saving process was prevented by invoking
preventSave()
method
-