Step 3 - Running a Vaadin Legacy CDI application with MPR and Flow
- Updating to the correct CDI version
- Handling of CDIUI annotation
- What to do with CDIView
- What to do with ViewScopes
- Next step
|
Note
| This step is needed in case your Vaadin 7 or 8 application uses CDI. If it is not the case, go back to the framework selection. |
Updating to the correct CDI version
Update com.vaadin:vaadin-cdi to 10.0.0:
Source code
XML
<dependency>
<groupId>com.vaadin</groupId>
<artifactId>vaadin-cdi</artifactId>
<version>10.0.0</version>
</dependency>As of writing the beta release is only in vaadin-prereleases repository so you
need to add it to your pom.xml.
Source code
XML
<repositories>
<repository>
<id>vaadin-prereleases</id>
<url>https://maven.vaadin.com/vaadin-prereleases</url>
</repository>
</repositories>Handling of CDIUI annotation
Instead of @CDIUI use @Route.
Source code
Java
@CDIUI
@Theme("valo")
public class TodoUI extends UI {
@Override
protected void init(VaadinRequest vaadinRequest) {
setContent(new HorizontalLayout());
}
}can for instance be replaced with
Source code
Java
@Route("")
public class TodoUI extends Div implements HasLegacyComponents {
@PostConstruct
private void buildLayouts() {
setSizeFull();
add(new HorizontalLayout());
}
}|
Note
|
Annotations in the UI, such as @Theme and @Title and so on, will be dealt with later on in the tutorial.
Most of them have similar counterpart in either Flow or MPR.
|
What to do with CDIView
Any @CDIView should be updated to a Flow Route by wrapping them as a MprRouteAdapter<? extends View>
or re-writing it to be a Flow Component. See Migrating Views to Flow Routes
What to do with ViewScopes
All ViewScopes should be changed to RouteScopes e.g.
-
@ViewScopedto@RouteScoped -
@NormalViewScopedto@NormalRouteScoped
|
Note
|
In some projects CDI has ignored the archive and not instantiated objects as expected. This
is fixed by adding a beans.xml (empty is fine) file to src/main/webapp/WEB_INF.
|