Share Information / Global Session ?



How I get all the “users” in the application? If i wanna make a list of everyone online in the site? or to share information ?


Basically you will have multiple active instances of your application running.
So just use a shared object which holds all active users.

For example a static ArrayList which you of course must synchronize correctly on access…


let’s assume I have ArrayList , so on Application init I add , and on application close i remove ?

application close is for seesion end & window close ?

Yes, just add remove them and then update the GUI accordingly.

application close is on session on, there is no real way to detect when just the browser(window) is closed,
so you might have to just clean out old entries (or wait until the session times out)


To be slightly more accurate, with some browsers it is possible to detect window close and communicate that information to the server (in most cases - not including things like browser crash), whereas with others it is not possible. Furthermore, a page reload typically looks like window close to the client side of the application.

In general, you can try to react to window close but cannot rely on it and you might get into some complications if you do use it.

I see , so making chat with Vaadin seems a problem because I don’t know when a user is out from the window …

another thing , refresh pag is also invoke close method?

For some reason, window close listener gets fired multiple times for every time the window is opened in the same user session. I had a method written that moved the window on window close, (get position x and then move to x-20), and first time it would do it once, and then if the window got opened and closed again it would move it twice by 40, thrice by 60 etc…

For something like a user chat you could do a work around, and sort of “ping” the user base for a given user whenever the user does something like posts a message, tries to open a private message box etc.

For a dynamic user list, if you use the navigator7 especially, you could assign the username to the window, and then you could just check the MyAppWindow list of open windows and get the username for each. Even without the navigator7 Add-On, I think there is a way to check the number of user context session windows open (vaadin Application class objects), and get the username variable for each.

Also, for a general message board in the center, you could maybe set it as a static variable that all users access and update, that refreshes whenever an update is made to this chat window for all users.

Do you register the listener every time you show the window?

If it is the framework that does not clean up something it sets up itself, please
create a bug report
- but first check where the extra listeners come from.