Notifications

Notifications are pop-up messages displayed to inform users about activities, processes, and events in the application.

To show a notification, inject the Notifications bean into the view class and use its fluent interface. In the following example, a notification with default parameters is shown on the button click:

@Autowired
private Notifications notifications;

@Subscribe("helloButton")
public void onHelloButtonClick(ClickEvent<Button> event) {
    notifications.show("Hello");
}

Below is an example of a parameterized notification:

notifications.create("Hello")
        .withType(Notifications.Type.WARNING)
        .withPosition(Notification.Position.BOTTOM_END)
        .withDuration(3000)
        .show();

To display HTML content in a notification, pass the com.vaadin.flow.component.Html component to the show() or create() method. The content should have exactly one root element. For example:

notifications.show(new Html("<div>Hello<br>World</div>"));

You can also display a multi-line text using \n characters and a special CSS class:

notifications.create("First line\nSecond line")
        .withClassName(LumoUtility.Whitespace.PRE_LINE)
        .withDuration(5000)
        .show();