Vaadin Style Guide

Some years ago, Mr. Joshua Bloch published the book Effective Java, this book was like a good style guide for Java.

Please someone post something similar for Vaadin.
I have a couple of months with Vaadin and I’m not sure if everything I have coded is correct.

For example, create an instance of EntityManager in AppUI and share it for all views.

The best practice ( not just for Vaadin ) is that your EntityManager should be short lived, in your case you should put the EnityManagerFactory in your AppUI , in your views you create the em, use it and close it.

Creating an EntityManager is a cheap , creating the EnityManagerFactory is expensive.

Personally I keep the EntityManagers and Factories out of my UIs and Views, I try to use a MVP pattern where possible and only the Presenter / Controller has access to the EntityManager…

Also to make things easier look at the vaadin-cdi , Spring Integration addon or cdi-utils ( now split into ‘CDI MVP’ and ‘CDI Properties’ ), you can use CDI to inject an EntityManager instance into the presenter or view.