Skip to content

Notification

A toast-style notification that appears briefly to inform the user. Typically returned from an action handler rather than embedded statically.

new Notification("Operation completed successfully.")
PropertyTypeDefaultDescription
titleString""Bold heading line
textStringBody text
styleString""Inline CSS
cssClassesString""CSS class names
// text only
new Notification("Saved!")
// title + text
new Notification("Success", "Record has been saved.")
// builder
Notification.builder()
.title("Error")
.text("Could not connect to the server.")
.build()

The most common pattern is to return a Notification from an action handler so it appears as a toast after the action completes:

@Override
public Object handleAction(String actionId, HttpRequest request) {
if ("save".equals(actionId)) {
save(formData);
return new Notification("Saved!", "Your changes have been stored.");
}
return new State(this);
}

A Notification can also be placed statically inside a Form’s header to display a persistent message:

Form.builder()
.header(List.of(
Notification.builder().title("Draft").text("This record has unsaved changes.").build()
))
.content(formContent)
.build()