flow icon indicating copy to clipboard operation
flow copied to clipboard

Router: Multiple optional parameters support

Open fluorumlabs opened this issue 8 years ago • 9 comments

As a developer I want to have the same view being accessible using different routes with different parameters. For example:

  1. /forum/thread/<threadId> opens the thread view
  2. /forum/thread/<threadId>/<messageId> opens the same thread view and scrolls to specified message
  3. /forum/message/<messageId> -- same as above, but retrieves the threadId first, based on messageId

In current implementation we have

@Route(value = FORUM_THREAD_ROUTE /* /forum/thread */, layout = ForumView.class)
@RouteAlias(value = FORUM_MESSAGE_ROUTE /* /forum/message */, layout = ForumView.class)

and then

	@Override
	public void setParameter(BeforeEvent event, @WildcardParameter String parameter) {
		if(StringUtils.isNotEmpty(parameter)) {
			if (event.getLocation().getPath().startsWith(FORUM_THREAD_ROUTE)) {
				String[] segments = parameter.split("/");
				if (segments.length >= 1) threadIdParam = segments[0];
				if (segments.length >= 2) messageIdParam = segments[1];
			} else {
				String[] segments = parameter.split("/");
				if (segments.length >= 1) messageIdParam = segments[0];
			}
		}
	}

fluorumlabs avatar May 31 '18 07:05 fluorumlabs

There is now an implementation available as extension to Vaadin Flow by @fluorumlabs : https://vaadin.com/directory/component/url-parameter-mapping

samie avatar Sep 11 '18 13:09 samie

There is now an implementation available as extension to Vaadin Flow by @fluorumlabs : https://vaadin.com/directory/component/url-parameter-mapping

Yeah, that's me, the OP

fluorumlabs avatar Sep 18 '18 15:09 fluorumlabs

+1 for this feature

gualtierotesta avatar Dec 05 '18 07:12 gualtierotesta

Has there been any progress in that regard? The JAX-RS/Spring MVC like routing is a basic feature needed for any web framework. There is indeed this quite nice addon: https://vaadin.com/directory/component/url-parameter-mapping, but still it's not ideal. You still can't define 3 classes for routes like those:

  • /items
  • /items/:itemId
  • /items/:itemId/edit

Even in this addon you still need to read pattern from @UrlMatchedPatternParameter to decide which view has to be rendered. There is also problem with view lifecycle when you switch between those 3 routes immediatelly.

In Spring MVC you could just declare 3 different controllers naturally.

Wlodas avatar Dec 16 '19 09:12 Wlodas

We are currently working on #2740 "on the side", this could make sense IMO for the /items/:itemId/edit case mentioned by @Wlodas.

For this issue about multiple optional parameters, it could be a candidate after #2740 but due to other priorities, I cannot give any promises. Contributions would be welcome, if someone wants to contribute this, please drop a line here so we can think about the design part.

pleku avatar Dec 16 '19 10:12 pleku

To be decided which Vaadin 14 minor this lands into. Probably 14.4 even though window is still open for 14.3.

pleku avatar May 12 '20 11:05 pleku

Hi @pleku! Was any decision made yet in which 14.x it will end up?

Thanks!

bcersows avatar Sep 02 '20 06:09 bcersows

Hi @bcersows. There has not been an explicit decision yet since this is released as part of v17 today (🎂) and we are keeping our ears open for a month or so if there is any feedback on this. 14.4 is already being built so it looks like it will not make it. That would mean then 14.5 which should follow quite quickly after 14.4, but in practice somewhere in November ???

Please test this and the new route parameter handling (#2740) for Java views in Vaadin 17 and if it hits works nicely, let us know. I would love to ship this in 14-series ofc. as soon as possible, but we also don't want to ship anything that "hasn't been battle proven" to the LTS either. I hope you understand why we take time with this.

pleku avatar Sep 02 '20 09:09 pleku

Thanks for the fast reply, and I'll test it there, yes!

Edit: I love it!
Documentation link for the lazy: https://vaadin.com/docs/v17/flow/routing/tutorial-router-templates.html

bcersows avatar Sep 02 '20 10:09 bcersows