flow icon indicating copy to clipboard operation
flow copied to clipboard

Allow modifying Query Parameters list

Open OlliTietavainenVaadin opened this issue 3 years ago • 1 comments
trafficstars

Describe your motivation

Sometimes, you want to add or remove items from the query parameters before e.g. rerouting. This could happen e.g. if the query parameters contain information that shouldn't be displayed in the URL bar and should only be stored in the session. Currently this requires recreating the QueryParameters object, which is clunky at best:

QueryParameters queryParametersAfterLogin = new QueryParameters(
      parameters.entrySet().stream()
        .filter(e -> !e.getKey().equals("pwd"))
        .filter(e -> !e.getKey().equals("user"))
        .filter(e -> !e.getKey().equals("client"))
        .collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue)));

Describe the solution you'd like

add(key) and remove(key) methods provided in the QueryParameters object

OlliTietavainenVaadin avatar Sep 19 '22 10:09 OlliTietavainenVaadin

There's some merit to QueryParameters being immutable. There could still be mutators but they would then return a new immutable object instead of modifying the existing ones.

Your usage example could then look like this:

QueryParameters queryParametersAfterLogin = parameters.excluding("pwd", "user", "client");

Adding a single entry could be

QueryParameters added = parameters.including("foo", "bar");

Adding multiple entries could be through accepting a Map (which plays nicely with the new-ish Map::of shorthands):

QueryParameters addedMany = parameters.includingAll(Map.of("key1", "value1", "key2", "value2"));

Legioth avatar Sep 21 '22 09:09 Legioth

This ticket/PR has been released with Vaadin 24.2.0.alpha5 and is also targeting the upcoming stable 24.2.0 version.

vaadin-bot avatar Aug 02 '23 18:08 vaadin-bot