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.
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
[/quote]
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, …).
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 !
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) :
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 ?