How to create a MVP architecture with Vaadin + Spring?

I’d like to create the following simple MVP architecture:

  • View classes that are simly the vaadin layout, components, styles. nonfunctional. The views should be tied to the current ViewScope/SessionScope, therefore I use @UIScope of https://github.com/peholmst/vaadin4spring

  • Presenters should have the view injected, register listeners on the view components, handle user input and delegate to the model services

Problem: when I inject the view into the presenter, the view is recreated, thus presenter and view are not in the same scope. So the binding will not work. What can I change to achieve the design described above?

@VaadinComponent
@UIScope
public class LoginView {
    //form fields, buttons
}

@Controller
public class LoginPresenter implements ClickListener {
    @Autowired
    private LoginView view;

    @PostConstruct
    public void bind() {
        view.getLoginButton().addClickListener(this);
    }   

    @Override
    public void buttonClick(ClickEvent event) {
        //validate input and login
    }   
}

In our current project we want to combine the technologies Spring, Spring Boot, and Vaadin. We want to achieve decoupling in the same way member sound described above, and have the same problem and no real idea for a solution, yet.

@Petter:
Do you have a hint concerning this problem?

I just discovered the
crossposting
at stackoverflow.com today. The discussion already continued there.

What stack overflow forgot is to mention this blog entry
https://vaadin.com/web/magi/home/-/blogs/model-view-presenter-pattern-with-vaadin

The usage of DI technology is not so important in my opinion. You just have to create clean models, views and presenters.

I found the blog entry you mentioned, too (it is the first Google hit for “vaadin model view presenter”).

IMHO the example is not very helpful for the problem discussed here because it is to far away from a real-world solution (in a frontend with a more complex layout you want to define and layout the widgets individually).

Hello Meik,

of course this is a very simple example. But as more complex your UI becomes as better will your MVP perform. It is a lot more boiler code you have to write but you have some significant advantages (JUnit testable eg).