weixin_39927799 2020-11-30 09:01
浏览 0

Make VaadinSession non-global.

Originally by

It seems that using one VaadinSession that is shared between all VaadinService instances causes more problems than what it fixes.

We should go back to the Vaadin 6 way of having one storage object for each defined servlet by: 1. Change the logic for how the VaadinSession is stored in HttpSession so that there is one instance per VaadinService by using VaadinService.getServiceName() in the attribute name. 1. Remove the now unnecessary VaadinSession parameter from some methods in e.g. VaadinService. 1. Rename VaadinSession to VaadinServiceSession to better tell what it is related to.

The only identified use case that gets "broken" by this change is if there are two servlets with different UI classes (e.g. / with UserUI and /admin with AdminUI) that should still share data. This can still be achieved either by using only one servlet and a UIProvider for serving different UIs for different paths or by storing the global data e.g. in HttpSession instead of in VaadinSession.

该提问来源于开源项目:vaadin/framework

  • 写回答

10条回答 默认 最新

  • weixin_39927799 2020-11-30 09:01
    关注

    Originally by archie172

    From the forum discussion, here are my suggestions:

    1. Add an optional <init-param> to VaadinServlet that configures this "scope" (could simply be a prefix to the HTTP seession key).
    2. Add protected onScopeStart() and onScopeStop() methods to VaadinServlet that can be overridden by subclasses. These methods would be invoked following the creation/destruction of a specific "scope".
    3. Move the lock from VaadinSession to the new scope.

    This is all just another way of saying that the old notion of a "Vaadin application" (which used to be represented by the Application class) needs to be put back in some form.

    Call it a "scope" if you want to, but it's ultimately the same thing. Removing it without providing an equivalent replacement was a mistake in the first place.

    评论

报告相同问题?