Vaadin Flow: How to get current URI
Asked Answered
B

2

7

I need to get the current servers name an all the other information stored in the URI. In Vaadin 8 it was accessible thru the Page by calling something like this:

URI uri = Page.getCurrent().getLocation();

In Flow the Page does not contain such information: enter image description here

An neither does the Router afaik.


How do I get the URI?

Thank you in advance.

Bohrer answered 6/2, 2019 at 14:16 Comment(0)
B
12

Update Feb 2021

Since Vaadin 19 there is a new Page method called fetchCurrentURL which will actively poll the current url form the frontend.

see: commit


Old and potentially problematic workaround

The URI can be retrieved using this:

VaadinServletRequest req = (VaadinServletRequest) VaadinService.getCurrentRequest();
StringBuffer uriString = req.getRequestURL();
URI uri = new URI(uriString.toString());
Bohrer answered 15/3, 2019 at 13:46 Comment(0)
B
2

There is no direct way of doing this, but a feature request is open for this case: https://github.com/vaadin/flow/issues/1897.

Bradfield answered 6/2, 2019 at 14:33 Comment(1)
This is no longer true as the feature has been implemented.Bohrer

© 2022 - 2024 — McMap. All rights reserved.