https://vaadin.com/docs/-/part/framework/advanced/advanced-cdi.html
Add dependency to Maven POM
<dependency> <groupId>javax</groupId> <artifactId>javaee-api</artifactId> <version>7.0</version> </dependency> <dependency> <groupId>com.vaadin</groupId> <artifactId>vaadin-cdi</artifactId> <version>LATEST</version> </dependency>
Add empty file /src/main/webapp/WEB-INF/beans.xml
Convert UI class to CDIUI style
(1) Add @CDIUI("") to class (just above @Theme)
(2) Remove generated VaadinServlet class
@WebServlet(urlPatterns = "/*", name = "RootUIServlet", asyncSupported = true)
@VaadinServletConfiguration(ui = RootUI.class, productionMode = false)
public static class RootUIServlet extends VaadinServlet {
}
First, use a Java EE container (I'm working on WildFly)
Install: add dependency from Maven (both Vaadin CDI Add-on and Java EE API)
Preparing for CDI
@CDIUI("")
Normally need not path (so under context)
The addon manages CDI views with a special view provider and enables view scoping
Preparing the UI for CDI Navigation
@CDIUI("mycdiui")public class MyCDIUI extends UI { @Inject CDIViewProvider viewProvider; @Override protected void init(VaadinRequest request) { Navigator navigator = new Navigator(this, this); navigator.addProvider(viewProvider); // Navigate to start view navigator.navigateTo(""); }}View
@CDIView("main")public class MainView extends CustomComponent implements View {Producer:
class InputPanel extends Panel { @Inject private javax.enterprise.event.Event<MyEvent> event; public InputPanel() { super("Input"); TextField editor = new TextField(); Button save = new Button("Save", e -> // Java 8 event.fire(new MyEvent(editor.getValue()))); setContent(new VerticalLayout(editor, save)); } }Consumer:
@UIScoped class DisplayPanel extends Panel { Label display = new Label("-nothing to display-"); public DisplayPanel() { super("Display"); setContent(display); } void myEventObserver(@Observes MyEvent event) { display.setValue("Observed: " + event.getName()); } }Communications between UIs (skipped for now)