System-like notifications

Hi,

I would like to know if there’s any way to show a notification that looks and behaves like the system ones. I could achieve something very similar with the Notification class but there are two things I still don’t know how to get:

  • No closing cross
  • Link all over it, so when you click on it you go somewhere else

Thank you!

As nobody replies, I guess that’s not possible?

Hi,

I took a quick look at the code and seems you could do this from the client side (maybe even with just an extension). The key parts seem to be that you need to set VNotification.STYLE_SYSTEM style for the notification when showing it, and then you need to add a NotificationRedirect to it, like this:

VNotification n = VNotification.createNotification(1000 * 60 * 45,
                    uIConnector.getWidget());
            n.addEventListener(new NotificationRedirect(url));
            n.show(html.toString(), VNotification.CENTERED_TOP,
                    VNotification.STYLE_SYSTEM);

Seems that the NotificationRedirect is a private class, but it’s just a very simple implementation of VNotification.EventListener so it should be trivial to reimplement in your extension.

Oh thank you very much Teppo, I think this will make it, but where do I get the UIConnector from?

That parameter is just the ‘owner’ widget of the overlay, it does not have to be the UI instance. This is used just for finding the ApplicationConnection instance if/when needed. If you create the Notification from an extension which extends the UI, you can get the UI connector at the extend(ServerConnector) call. Then you can just cast if to a ComponentConnector and call getWidget() on it.

Also, I think you can even pass in a null without any ill effects, other than possibly a warning in the client-side debug.

Oh well I didn’t read carefully the first answer… I don’t know how to make an extension or anything about the client side. I’ve tried to use the code in the server side but the VNotification class is not found in run time.
I’m afraid I’ll have to move on without consistent error messages all over my site, but I hope your answer will be useful for someone.

There are some mini-tutorials about client side programming and extensions
here
and more on client side development
in the book
(first see the
chapter on Vaadin architecture
if not familiar with it) in case you want to give it a try.