Вопрос

I'd like to develop a vaadin application with spring. A user should be able to login and see uer-specific pages. I he comes to the site from a different browser window, it would be handy if the user is still logged in, so preserves the session.

Now I wonder which scope to use for this purpose? Vaadin and Spring offer a @Scope("session"), @Scope("ui") and a @Scope("prototype"). Should I just place all of my *View and *Presenter classes in the session scope?

Or would it be better to have the view annoted with prototype, so that each time a pages is changed the page is recreated with updated data? In this case, should then the presenters be still session scope, or also prototye?

Or should I at all use the ui scope that's provided by vaadin4spring boot addon? This would then create a new "uiSession" for every new tab.

@Scope("session")
class MyPresenter {
    //each view should be wired to a presenter
    @Autowired
    private MyView view;
}

@Scope("prototype") //"session", "ui"?
class MyView extends VerticalLayout {
    @PostConstruct
    public void init() {
        addComponent(new Label("time is: " + new Date()));
    }
}
Это было полезно?

Решение

vaadin stores (large amounts of) state in the session. state is pretty much anything, that is visible to the client in the browser. the ui scope is what you should use, if any component is involved. even if ui and session seem the same, you should stick to ui to prevent raceconditions and worse against the vaadin code.

in your example above, view is definetly ui, because it is a component. this makes the presenter ui also as it holds reference to an ui scoped component and will for sure tap into events from it or read data etc.

Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top