vaadin / multiplatform-runtime

4 stars 1 forks source link

Accessing legacy UI in afterNavigation of page with parameter causes IllegalArgumentException #103

Closed dbenninger closed 2 years ago

dbenninger commented 2 years ago

Vaadin 8.14.2 / 14.7.5

Accessing the legacy UI in the afterNavigation callback of a page implementing HasUrlParameter throws

IllegalArgumentException: Navigation target 'com.example.application.views.helloworld.PageWithParameter' requires a parameter.

To reproduce: 1) Unpack my-app-page-with-parameter.zip 2) Run the application 3) Go to http://localhost:8080/pagewithparameter/test

TatuLund commented 2 years ago

The legacy UI.getCurrent() works under MPR differently than normal. It will trigger creation of new UI instance. Now that seems to trigger some activity in Router as well, as it needs to check for @LegacyUI annatotation. Now it is that process that triggers the exception. Whether this is a design limitation or not, I do not know yet.

java.lang.IllegalArgumentException: Navigation target 'org.vaadin.mprdemo.PageWithParameter' requires a parameter.
    at com.vaadin.flow.router.internal.HasUrlParameterFormat.checkMandatoryParameter(HasUrlParameterFormat.java:272)
    at com.vaadin.flow.router.internal.AbstractRouteRegistry.getTargetUrl(AbstractRouteRegistry.java:281)
    at com.vaadin.flow.server.SessionRouteRegistry.getTargetUrl(SessionRouteRegistry.java:198)
    at com.vaadin.mpr.core.PathResolver.findPathString(PathResolver.java:78)
    at com.vaadin.mpr.core.PathResolver.getTopNavigationTarget(PathResolver.java:43)
    at com.vaadin.mpr.core.AbstractMprUIProvider.getLegacyUI(AbstractMprUIProvider.java:79)
    at com.vaadin.mpr.core.AbstractMprServlet.getCurrentUI(AbstractMprServlet.java:99)
    at com.vaadin.util.CurrentInstance.get(CurrentInstance.java:90)
    at com.vaadin.ui.UI.getCurrent(UI.java:936)
    at org.vaadin.mprdemo.PageWithParameter.afterNavigation(PageWithParameter.java:30)

You can workaround this using @OptionalParameter

    @Override
    public void setParameter(BeforeEvent beforeEvent, @OptionalParameter String name) {
        this.name = name;
    }

This issue is not limited to Vaadin version 14.7.5