v8 to v14 routing problems

Hi all,

I’m migrating from Vaadin8 to Vaadin14.
I read the docs, but I can’t find the solution to the following problem. Can anyone please help me?

This is my web.xml:

<web-app>

    <context-param>
        <param-name>productionMode</param-name>
        <param-value>false</param-value>
    </context-param>

    <servlet>
        <servlet-name>ReportMachine servlet</servlet-name>
        <servlet-class>com.marcozanon.reportmachine.AUiServlet</servlet-class>
        <init-param>
            <param-name>UI</param-name>
            <param-value>com.marcozanon.reportmachine.AApplicationUi</param-value>
        </init-param>
<!--
        <init-param>
            <param-name>widgetset</param-name>
            <param-value>com.marcozanon.reportmachine.widgetset.CustomWidgetSet</param-value>
        </init-param>
-->
        <init-param>
            <param-name>closeIdleSessions</param-name>
            <param-value>false</param-value>
        </init-param>
    </servlet>
    <servlet-mapping>
        <servlet-name>ReportMachine servlet</servlet-name>
        <url-pattern>/*</url-pattern>
    </servlet-mapping>

    <session-config>
        <session-timeout>5</session-timeout>
    </session-config>

    <context-param>
        <param-name>heartbeatInterval</param-name>
        <param-value>60</param-value>
    </context-param>

</web-app>

If I compile and run the application, everything I see is:

Could not navigate to ''

Reason: Couldn't find route for ''

Available routes:

This detailed message is only shown when running in development mode.

I thought this was due to missing @Route annotations, so I added one to the default class AView:

@com.vaadin.flow.router.Route("")
@PreserveOnRefresh
public class AView extends VerticalLayout {

  public AView() {
      this.add(new Text("TEST"));
  }

}

but the error still shows up.

If I change web.xml to:

    <servlet-mapping>
        <servlet-name>ReportMachine servlet</servlet-name>
        <url-pattern>/</url-pattern>
    </servlet-mapping>

(i.e.: no wildcards in url-pattern), then the error goes away and I see a blank page.
No way AView’s constructor is run.

Any ideas? I read the documentation and the examples, maybe it’s just a small detail, but I can’t figure it out…

Thanks a lot,
MZ

You need a view annotated with @Route , that’s true.

Generally that’s enough.
I believe you have issues because you are using a specific config with web.xml file.

We don’t recommend to use a custom UI. The UI class is still available in the application
but application should use a default UI class otherwise some unexpected things may happen.

I would recommend to avoid using web.xml at all.
Try to start with https://github.com/vaadin/skeleton-starter-flow which has the minimal configuration
to start V14 application.

Hi Denis, and thanks for replying.

I decided to follow your advice, i.e.: reduce web.xml at minimum. I will need a custom servlet, but not at the moment, so I put web.xml like this:

<web-app>

    <context-param>
        <param-name>productionMode</param-name>
        <param-value>false</param-value>
    </context-param>

    <session-config>
        <session-timeout>5</session-timeout>
    </session-config>

    <context-param>
        <param-name>heartbeatInterval</param-name>
        <param-value>60</param-value>
    </context-param>

</web-app>

Then I selected the default target:

@com.vaadin.flow.router.Route("")
@SuppressWarnings("serial")
public class AUi extends VerticalLayout implements ErrorHandler {

    public AUi() {
		// code here...
	}

}

Unfortunately, AUi’s constructor is never run.
Instead, all I see when I connect to localhost:8081 (or localhost:8081/) is Jetty listing some directory content (I can’t understand which directory: not my .war file).

Is there anything else I’m missing?

The project you pointed me to simply adds a @Route on MainView, so I can’t find where the problem is here…

Thanks very much for your help,
MZ

I made some tests and it seems the Route annotation is completely ignored in my code above…

Maybe Jetty (9.4.14) can’t read it?!

Thanks,
MZ

Ok, I got it: I completely removed web.xml from the .war file, and it works!

Thanks Denis for your help.

I still don’t understand why the documentation says that web.xml is not required, while it seems to me it is concretely banned…

Thanks,
MZ

If you see some issues with documentation please create a ticket.
It will help us to improve it.

Done: https://github.com/vaadin/flow-and-components-documentation/issues/642.

Thanks,
MZ

This worked fine for me (web.xml version 3.1)

<web-app xmlns="http://xmlns.jcp.org/xml/ns/javaee"
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee
                             http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd" version="3.1">

        <context-param>
            <param-name>productionMode</param-name>
            <param-value>false</param-value>
        </context-param>

        <session-config>
            <session-timeout>5</session-timeout>
        </session-config>

        <context-param>
            <param-name>heartbeatInterval</param-name>
            <param-value>20</param-value>
        </context-param>

</web-app>

Johannes Tuikkala:
This worked fine for me (web.xml version 3.1)

It didn’t work for me: no errors, but the web.xml file was completely ignored (I put it into src/main/webapp/WEB-INF and it was included in the final .war package),

thanks,

MZ

Marco Zanon:
Hi all,

I’m migrating from Vaadin8 to Vaadin14.
I read the docs, but I can’t find the solution to the following problem. Can anyone please help me?

This is my web.xml:

<web-app>

    <context-param>
        <param-name>productionMode</param-name>
        <param-value>false</param-value>
    </context-param>

    <servlet>
        <servlet-name>ReportMachine servlet</servlet-name>
        <servlet-class>com.marcozanon.reportmachine.AUiServlet</servlet-class>
        <init-param>
            <param-name>UI</param-name>
            <param-value>com.marcozanon.reportmachine.AApplicationUi</param-value>
        </init-param>
<!--
        <init-param>
            <param-name>widgetset</param-name>
            <param-value>com.marcozanon.reportmachine.widgetset.CustomWidgetSet</param-value>
        </init-param>
-->
        <init-param>
            <param-name>closeIdleSessions</param-name>
            <param-value>false</param-value>
        </init-param>
    </servlet>
    <servlet-mapping>
        <servlet-name>ReportMachine servlet</servlet-name>
        <url-pattern>/*</url-pattern>
    </servlet-mapping>

    <session-config>
        <session-timeout>5</session-timeout>
    </session-config>

    <context-param>
        <param-name>heartbeatInterval</param-name>
        <param-value>60</param-value>
    </context-param>

</web-app>

If I compile and run the application, everything I see is:

Could not navigate to ''

Reason: Couldn't find route for ''

Available routes:

This detailed message is only shown when running in development mode.

I thought this was due to missing @Route annotations, so I added one to the default class AView:

@com.vaadin.flow.router.Route("")
@PreserveOnRefresh
public class AView extends VerticalLayout {

  public AView() {
      this.add(new Text("TEST"));
  }

}

but the error still shows up.

If I change web.xml to:

    <servlet-mapping>
        <servlet-name>ReportMachine servlet</servlet-name>
        <url-pattern>/</url-pattern>
    </servlet-mapping>

(i.e.: no wildcards in url-pattern), then the error goes away and I see a blank page.
No way AView’s constructor is run.

Any ideas? I read the documentation and the examples, maybe it’s just a small detail, but I can’t figure it out…

Thanks a lot,
MZ

Hey! I have the same problem. I am trying to run the program which is given over here → https://vaadin.com/docs/v14/flow/advanced/tutorial-dynamic-content.html

And what I get is Vaadin every time tries to find the route inside the @Route and does not get the urlPatterns inside the @WebServlet.

What can be the problem? your help will be greatly appreciated!
Thanks!