Vaadin lets you build secure, UX-first PWAs entirely in Java.
Free ebook & tutorial.
MVP and CDI
This is a general question for how to best do Model View Presenter with Vaadin and CDI.
The normal MVP with Vaadin essentially has a section like the below in the UI
view = new View(); presenter = new Presenter(view); setContent(view);
If you're using something like the below with CDI instead:
@CDIUI public class MyUI ... } @CDIView public class MyView ... }
it's unclear where the presenter is created and how it applies to the View. The obvious way is to inject the view in the presenter and the presenter in the view, so the presenter can access the view properties and the view can create the presenter, but of course that leads to a Bean Circular Dependency.
It's important to be able to inject a DAO into the presenter, so it would seem to indicate that I need to inject the presenter somewhere.
The only thing that comes to mind is @Dependent scoping the presenter and setting the view into the presenter via a setter called from the view, so the presenter would be injected into the view, but not the other way around.
Is there a more elegant way, possibly involving scoping?
I would inject the @Dependent scoped presenter into the view, then invoke a setView() method on the presenter in a @PostConstruct method.
That is what I ended up doing an it works pretty well