Router: Multiple optional parameters support
As a developer I want to have the same view being accessible using different routes with different parameters. For example:
/forum/thread/<threadId>opens the thread view/forum/thread/<threadId>/<messageId>opens the same thread view and scrolls to specified message/forum/message/<messageId>-- same as above, but retrieves thethreadIdfirst, based onmessageId
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];
}
}
}
There is now an implementation available as extension to Vaadin Flow by @fluorumlabs : https://vaadin.com/directory/component/url-parameter-mapping
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
+1 for this feature
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.
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.
To be decided which Vaadin 14 minor this lands into. Probably 14.4 even though window is still open for 14.3.
Hi @pleku! Was any decision made yet in which 14.x it will end up?
Thanks!
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.
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