Query Parameters
It is possible to get any query parameters contained in a URL, for example ?name1=value1&name2=value2
.
Use the getQueryParameters()
method of a Location
instance to access query parameters.
You can obtain the Location
instance through the BeforeEnterEvent
parameter of the BeforeEnterObserver::beforeEnter
or the BeforeEvent
parameter of the HasUrlParameter::setParameter
method.
Note
|
A Location object represents a relative URL made up of path segments and query parameters, without the hostname, that is new Location ("book/search?keyword=Vaadin") .
|
Example: Retrieving query parameters from a BeforeEvent
.
@Override
public void setParameter(BeforeEvent event,
@OptionalParameter String parameter) {
Location location = event.getLocation();
QueryParameters queryParameters = location.getQueryParameters();
Map<String, List<String>> parametersMap = queryParameters
.getParameters();
}
Note
|
getQueryParameters() supports multiple values associated with the same key, for example https://example.com/?genre=fiction&restrictions=16+&genre=classic will result in the corresponding map {"genre" : ["fiction", "classic"], "restrictions": ["16+"]}} .
|
6C1E58A3-2A6E-45C1-9459-54EF83A8671C