Persist UI state

Hi everone !

I tried to find any information on the following subject with no success : is there a way to store/retrieve the UI sate through sessions for a user ?

Use case :
1/ user navigates through the application, resize table columns, changes their order, opens new tabs etc…
2/ User session expires (inactivity or user leaved the application)
3/ User comes back into the application : the UI state is restored from last session (opened tabs, column order & visibility…)

I understood that by default Tomcat persists session between crashes, but obviously when Vaadin expires the user session, the UI state is lost.

Any idea of how to make this in a clean way ?

How about just setting session timeout to be -1?

Thank you for your suggestion. I am still not able to test session restore because I face another issue : [quote]
Fatal error in serialization of the application: Class com.vaadin.ui.Panel must implement serialization
There is a @SuppressWarnings(“serial”) in the Panel class. Is this supposed to work despite this ?


SuppressWarnings serial does not make it less serializable - it only states that the id used in the serialization is changes for any class changes. So as long as you do not update Vaadin version (or the new version has identical Panel class) it should serialize/deserialize without a problem. In practice this is not a problem - one updates Vaadin libraries only when the application version is updated. It should be ok to ask users to log in the application after application version have been updated.

This is probably a bad idea with respect to the memory consumption on the server.

You could look into the
SessionGuard add-on
(or appropriate portal configuration if e.g. on Liferay) to handle inactivity.

As for the user closing the browser and coming back later, you can extend the session timeout but using the server sessions for extremely long times is not ideal, and you might be better off developing your own mechanism that saves the aspects of state you are interested in and cleans that storage periodically.

If there is little state information, having the key state in the URI might make sense, as long as you are careful about security (data leaks, not concatenating strings from the URI with DB queries or showing them to the user as HTML, …).

It’s to heavy stuff to save all UI state data and reset it through the API. We decided to serialize the app and use Tomcat Persistent Manager.

Thank you for your advices

I would guess that one could configure java server to serialize inactive sessions on disk before we run out of heap.

Hi Vaadin guys !

Just to let you know that I managed to do what I wanted. It was so simple that it took my days to have the idea !

User logs. He uses the app. At some regular points I store the MainWindow object into a cache (persisted on disk). When user logs again, I read the cache and calls Application.setMainWindow(cachedWindow), which updates the Window Application reference (so no context/session issues) !

Sorry I couldn’t be more precise about what I was trying to do. If I would maybe you would have been able to tell me that it was enough to save/restore the Window object ! :stuck_out_tongue:


Hi there,

I have some weird behavior which is probably due to what I have done to persist my UI state (see above).

This issue is related to modal windows. This is the code I use to close the modal window (called from a Form class) :


When this line is executed after I restored my UI by calling Application.setMainWindow(MySerializedWindow), the modal Window doesn’t close itself on screen and the UI goes out of sync (because the modal window was actually removed from the application windows) :

20 janv. 2011 09:16:13 com.vaadin.terminal.gwt.server.AbstractCommunicationManager handleVariableBurst
ATTENTION: Warning: Ignoring variable change for non-existent component, VAR_PID=PID40

What is weird is that everything else repaints normally but the modal window stays in front of the main window.

Seems that this is a repaint issue…does anyone know what could do this ?

Is this a bug in Vaadin ? Do you think what I have done (serializing my vaadin app to a cache) is acceptable regarding Vaadin philosophy ? I know that Vaadin is supposed to be serializable because of Google App Server support.

I think you should be able to serialize a session from your code, but serializing just the main window is probably not possible. Vaadin sessions have various state stuff that also needs to be serialized. You possibly need to extend ApplicationServlet or something else at that level.

As Joonas suggested, the Java server that you’re using might support persisting a session. At least Tomcat supports it, but I don’t know if and how it can be requested from the session itself.

OK I can understand that but what makes me think I am close to do this, is that on the server side the modal closes well and it is only a client side out of sync error.

Will you (vaadin team) take a look if i provide a sample project ?

thanks anyway.