Vaadin App using Java Pure or Html + Java?

I have been a java programmer for 10 years… for the last 5 years I have been developing applications using GWT. I have been interested in Vaadin for a friend, and I would like to know which is the most common pattern to use to create professional applications in this framework.

  • Using Java Pure
  • Using Html + Java

The Java first approach is probably the most common, but what works best for you depends of course on what exactly you’re doing, your requirements, your skillset, and your preferences.

Probably a good practice is to separate the view from the java code. In fact in GWT we use the MVP pattern trying to separate them. I think it would be applicable in Vaadin, to leave all event handling and business logic in other classes (Presenter). Is there any predefined good practice in Vaadin to achieve that?

I’d say MVP is a solid practice with Vaadin as well, as long as you don’t overdo it.

//The presenter

public class Presenter {    
    public Presenter(Display display) {
        display.clickComponent().addClickListener(event -> {
            Notification.show("You Clicked a vaadin button");
        });
    }
    interface Display {
        public ClickNotifier<Button> clickComponent();
    }
}

//The view implementation

public class ViewImpl extends Div implements Presenter.Display {

    private TextField name;
    private Button acceptButton;

    public ViewImpl() {
        this.name = new TextField("Message");
        this.acceptButton = new Button();      
        add(name, acceptButton);
    }    

    @Override
    public ClickNotifier<Button> clickComponent() {
        return acceptButton;
    }
}