Search code examples
vaadinvaadin7

auto closing Vaadin window after delay


I wanted to create my own message box class so that I can create different types of messages (w/o buttons e.g.). For the tray messages I want an auto close after lets say 5sec delay.

I've searched the internet: I found very old posts suggesting ProgressIndicator or some "newer" ones (4yo) with push/poll/threading. I really wonder if there is a neat solution meanwhile in Vaadin 7.6. Push/poll seemed a little too complicated for me to understand the mechanics (beginner...).


Solution

  • TLDR: Either you use Push/poll techniques or you need to write your brand new component in GWT. The choice is yours

    To fully understand why is that you need to know how Vaadin or/and web applications work. Lets take your example: you want to tell the browser in some way to close the window after some delay (5 sec). You can achieve desired effect in two different ways:

    • use setTimeout in JavaScript
    • send a message from the server to the browser

    setTimeout in Vaadin: of course there is no such method in Vaadin since this framework uses pre-compiled GWT components. So you would need to either find a component in Vaadin addons repo or write your own. GWT is not JavaScript - this is true but you can still attach your own JavaScript file with any GWT component.

    Sending a message from server to the browser means basically Push/Polling. No other way around. Vaadin actually support both so the only thing you need is to learn about them.

    There is also a hack but I wouldn't recommend this approach. In general you can execute pure JavaScript code at runtime using:

    JavaScript.getCurrent().execute("alert('Hello')");
    

    But should you want to go this way you will have hard time managing your popups since Vaadin framework will not expect you to close windows that he is responsible for.