Vaadin and MVP Pattern

Hi folks,

i’m writing my first vaadin application and i looking for some best practices. I reader this article https://vaadin.com/web/magi/home/-/blogs/model-view-presenter-pattern-with-vaadin and want use mvp pattern for my application.

At the moment i cant understand how i can connect it with my
MainUI extends UI
where my application start.

There are other resources about mvp patterns in Vaadin?

Tnx.

The view implementation is a component.

public class MyUI extends UI {
    @Override
    public void init(VaadinRequest request) {
        // Create the content root layout for the UI
        VerticalLayout content = new VerticalLayout();
        setContent(content);

        // Create the model and the Vaadin view implementation
        CalculatorModel    model = new CalculatorModel();
        CalculatorViewImpl view  = new CalculatorViewImpl();
    
        // The presenter binds the model and view together
        new CalculatorPresenter(model, view);
    
        // The view implementation is a Vaadin component
        content.addComponent(view);                
    }
}

Note that the MVP pattern actually
not
really so commonly used in Vaadin applications, even though the article says so. Some projects use it extensively, but usually the two-way abstraction is just a distraction. It is useful
if
you have or expect to have more than one view implementations.

So, you should start from the
basic application architecture
, and unless you specifically need MVP, you could consider it.

Tnx Marko,

now i understand how use it. Maybe i will continue with the actual implementation. I’m using a lot the navigator for switch beteween sub-view and maybe the two-way abstraction is just too much atm. But it’s good to know mvp too :slight_smile: