Docs

Documentation versions (currently viewingVaadin 14)

You are viewing documentation for an older Vaadin version. View latest documentation

Creating V7 and V14+ CDI applications side-by-side

If you have an application developed using Vaadin 7 and CDI, you have the option to keep your legacy code untouched and continue developing new pages with V14+.

You will also be able to use CDI beans, e.g. SessionScoped beans, in both V14+ and Vaadin 7 parts of your application. The following instructions are step-by-step guide on how to adopt this approach with Vaadin 14. The same instructions can be followed to do the same with Vaadin 15+. You just need to use the Vaadin version of your choice.

  1. Add Vaadin 14 to your maven dependencies.

    <dependencyManagement>
        <dependencies>
            <dependency>
                <groupId>com.vaadin</groupId>
                <artifactId>vaadin-bom</artifactId>
                <type>pom</type>
                <scope>import</scope>
                <version>14.12.4</version>
            </dependency>
        </dependencies>
    </dependencyManagement>
    <dependencies>
        <dependency>
            <groupId>com.vaadin</groupId>
            <artifactId>vaadin-core</artifactId>
        </dependency>
    </dependencies>
  2. Exclude conflicted dependencies between Vaadin 7 and Vaadin 14 which are jsoup and atmosphere-runtime from Vaadin 7 in your pom.xml, like shown in the following example:

    <dependency>
        <groupId>com.vaadin</groupId>
        <artifactId>vaadin-server</artifactId>
        <version>${framework.7.version}</version>
        <exclusions>
            <exclusion>
                <groupId>com.vaadin.external.atmosphere</groupId>
                <artifactId>atmosphere-runtime</artifactId>
            </exclusion>
            <exclusion>
                <groupId>org.jsoup</groupId>
                <artifactId>jsoup</artifactId>
            </exclusion>
        </exclusions>
    </dependency>
  3. Remove dependency of vaadin-cdi 1.* and add a dependency to mpr-cdi-v7 1.0.0.

    <dependency>
        <groupId>com.vaadin</groupId>
        <artifactId>mpr-cdi-v7</artifactId>
        <version>1.0.0</version>
    </dependency>
  4. Add the vaadin-cdi dependency. The version is not needed as it is defined by the vaadin-bom.

    <dependency>
        <groupId>com.vaadin</groupId>
        <artifactId>vaadin-cdi</artifactId>
    </dependency>
  5. Since the root path of your application is managed by Vaadin 7, you need to define the Vaadin 14 servlet manually, and set its url pattern to a value that doesn’t collide with any of the V7 servlets.

    @WebServlet(name = "Flow Servlet", urlPatterns = {
            MyFlowServlet.FLOW_SERVLET_ROOT + "/*" })
    public class MyFlowServlet extends CdiVaadinServlet {
        public static final String FLOW_SERVLET_ROOT = "flow";
    }
  6. Now, you can have both Vaadin 7 and Vaadin 14 parts of your application in one project. To navigate from Vaadin 7 part to Vaadin 14 part you can simply use the following line of code.

    getUI().getPage().setLocation(MyFlowServlet.FLOW_SERVLET_ROOT);

    And, to navigate from Vaadin 14 part to a Vaadin 7 view you can for example use an Anchor like the below code.

    Anchor anchor = new Anchor("/#!home", "Home");
    add(anchor);
  7. To have shared data between Vaadin 14 and Vaadin 7 parts, you can use SessionScoped beans that are shared for both V7 and V14 applications.

    @SessionScoped
    public class SecurityContext implements Serializable {
        private User currentUser = new User();
    
        public boolean signIn(String username, String password) {
            if (username == null || username.isEmpty())
                return false;
    
            currentUser.setUsername(username);
    
            return true;
        }
    }

0D8B2EA9-ACFB-4679-B8E0-50F6F1842F11