Magnolia 5.5 reached end of life on November 15, 2019. This branch is no longer supported, see End-of-life policy.
Alerts are modal messages that show up in the context the user is currently working in. You can use alerts to confirm that an action should be executed, inform the user of harmful consequences, or report the progress of a long-running action. Since alerts are modal they block the user interface.
To show alerts, inject the
UiContext
interface to your class. The UiContext
is implemented by AppContext
, SubAppContext
and Shell
, so if you have one of those at hand, just reuse them.
Usage examples:
@Inject public MyCustomClass(UiContext uiContext) { this.uiContext = uiContext; } // Show an ERROR alert. private openErrorAlert(String message) { uiContext.openAlert(MessageStyleTypeEnum.ERROR, "Error", "File upload failed.", "OK", null); } // Confirm deletion with a WARNING alert. private openConfirmationWarning(String message) { uiContext.openConfirmation(MessageStyleTypeEnum.WARNING, "Delete node?", "This action cannot be undone.", "Yes, Delete", "No", true, null);