Routing API questions

I have some questions about the Routing API.

Some context: I’m playing with the idea of having a QR code that points to a URL that initiates the creation of a new entity instance. The URL would contain some parameters to be used as attributes for the new instance. This points me to two requirements/questions.

  1. Is it even possible to create a new entity instance from the URL routing?
  2. Can I specify custom URL parameters? Like to specify some of the attributes to load into the new entity instance.

Hello @wwnjj13

Is it even possible to create a new entity instance from the URL routing?

Yes, it is possible. You should create a screen, register required route, subscribe for UrlParamsChangeEvent and do your things:

@Subscribe
private void onUrlParamsChanged(UrlParamsChangedEvent event) {
    Map<String, String> params = event.getParams();

    // handle passed parms & create new instance here
}

Can I specify custom URL parameters? Like to specify some of the attributes to load into the new entity instance

There is the only one restriction for URL params - they should be pairs of strings separated by “&”:

http://host:port/app/#main/new-something?param1=value1&param2=value2...

Just handle these params as you wish in UrlParamsChangeEvent listener.

Regards,
Daniil

1 Like