Hello everyone,
I would like to know how to make automatically disappear a SYSTEM notification type. I don’t why the method withHideDelayMs() isn’t working with this type of notification but it’s working perfectly well with the ERROR and WARNING type.
Thank you,
Thomas
Hi,
This is by design. SYSTEM
notifications are too important to auto hide them. If you’re really need to set hide delay you have 2 options:
- Use
com.vaadin.ui.Notification
directly. The example can be found inio.jmix.ui.sys.NotificationsImpl.NotificationBuilderImpl#createNotification
. - Extend
io.jmix.ui.sys.NotificationsImpl
and changeio.jmix.ui.sys.NotificationsImpl.NotificationBuilderImpl#createNotification
implementation so that system notification considers hide delay.
Regards,
Gleb
I tried recreate the createNotification in which I am setting a hide delay, but whatever I try, the notification won’t disappear.
Here is my code, if anyone now why.
protected Notification createNotification(String caption, String description, Notifications.NotificationType type) {
Notification vNotification;
if (Notifications.NotificationType.SYSTEM == type) {
vNotification = new Notification(caption, description);
vNotification.setDelayMsec(2500);
vNotification.setPosition(com.vaadin.shared.Position.TOP_CENTER);
vNotification.setStyleName("system");
} else {
vNotification = new Notification(caption, description, convertType(type));
vNotification.setDelayMsec(2500);
}
if (eventHub.hasSubscriptions(Notifications.CloseEvent.class)) {
vNotification.addCloseListener(e ->
eventHub.publish(Notifications.CloseEvent.class, new Notifications.CloseEvent(e.getNotification(), e.isUserOriginated()))
);
}
return vNotification;
}
@Override
public void show(String caption, String description, Notifications.NotificationType type) {
backgroundWorker.checkUIAccess();
Notification notification = createNotification(caption,description,type);
notification.show(ui.getPage());
}
It appears that the system
style is also checked on the client-side, so it no way to set hide delay for the system notification.
Alternatively, you can define custom style name, e.g.:
notifications.create()
.withCaption("Custom System Notification")
.withPosition(Notifications.Position.TOP_CENTER)
.withHideDelayMs(2500)
.withStyleName("custom-system")
.show();
And custom styles that make yout notification looks like system:
.v-Notification.custom-system {
@include valo-notification-bar-style(v-Notification);
@include valo-notification-system-style(v-Notification);
@include he-notification-system-style();
}
Gleb
Thank you so much!!