flow icon indicating copy to clipboard operation
flow copied to clipboard

Provide IDE warnings or compile time/run time exceptions for unsupported HasUrlParameter typed parameter

Open dmitrilc opened this issue 3 years ago • 2 comments

Describe your motivation

Currently, the interface HasUrlParameter<T> only works if the type parameter is one of the below types:

  • Long
  • Integer
  • String
  • Boolean

There is no compile time warning, IDE warning, annotation processor exception, or runtime exception of any kind when an unsupported type parameter is used. The app simply runs normally, but will only fail when attempting to navigate to the unsupported route.

The Java doc for the interface HasUrlParameter<T> does not even mention this.

Describe the solution you'd like

Most importantly, the Java doc for HasUrlParameter<T> should at least mention this limitation.

Other solutions that are somewhat acceptable are:

  • The app fails at compile time.
  • The app fails at run time.
  • The IDE provides warning.

Describe alternatives you've considered

Add these public APIs and guide new projects toward using them instead, HasStringRouterParameter, HasIntegerRouteParameter, HasLongRouteParameter, and BooleanRouteParameter.

Additional context

Related ticket: https://github.com/vaadin/docs/issues/368

dmitrilc avatar Jun 23 '22 00:06 dmitrilc

It's an really old issue ;) feature request to allow more types https://github.com/vaadin/flow/issues/4689

knoobie avatar Jun 23 '22 04:06 knoobie

Additional Information

When I use the route below with a custom Person pojo, the code compiles and runs. I can't navigate to it, but the route is indeed present in the "could not navigate to xxx route" page.

@Route(value = "personRoute", layout = MainLayout.class) //will be inside parent
@PermitAll
public class PersonRouteParameter extends HorizontalLayout implements HasUrlParameter<Person> {
    @Override
    public void setParameter(BeforeEvent event, Person parameter) {
        System.out.println(parameter);
    }
}

Could not navigate to 'personRoute'

Available routes:

...omitted
personRoute/:___url_parameter(null) (requires parameter)
...omitted

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

I thought it would throw an exception based on this loc https://github.com/vaadin/flow/blob/b2fb1f0c85ac1ca08ce097fabbb9003936aee40c/flow-server/src/main/java/com/vaadin/flow/router/ParameterDeserializer.java#L76, but I guess not.

dmitrilc avatar Jun 23 '22 13:06 dmitrilc