UI.getCurrent().navigate does not display the wanted page when being called from setParameter(BeforeEvent beforeEvent, @OptionalParameter String s)
See original GitHub issue-
Description: When using UI.getCurrent().navigate in a setParameter Method, the content of the page is not being displayed. I wanted to create some kind of fallback if no value for the given parameter has been found.
-
Minimal reproducible example:
@Route(value = "shop", layout = MainLayout.class)
public class CompanyPage extends Composite<Div> implements HasUrlParameter<String> {
....
@Override
public void setParameter(BeforeEvent beforeEvent, @OptionalParameter String s) {
company = companyRepository.getByCompanyLink(s);
if (company == null) {
//Rerturn to home if no company has been found.
UI.getCurrent().navigate("");
} else {
getContent().add(new H1(company.getName()));
}
}
-
Expected behaviour: Should show the content of my page i wanted to navigate to.
-
Actual behaviour: Shows nothing when trying to navigate to an other page then the value given in the Route of the class with the Parameter (example here:
Shop
). Something fails loading here.
Issue Analytics
- State:
- Created 5 years ago
- Comments:5 (4 by maintainers)
Top Results From Across the Web
Pass the parameter in Vaadin 14 between two routes
FullOrderView' requires a parameter. If I remove a "implements HasUrlParameter" and setParameter() I get an error. No route found for the given ...
Read more >Navigation issue in Vaadin - Why can't I navigate
I think I have an issue. When I want to navigate to a route, then I say. UI.getCurrent().navigate("Intranet");. Then I want to go...
Read more >How to use navigate method in com.vaadin.flow.component.UI
Gets the object representing the page on which this UI exists. getCurrent. Gets the currently used UI. The current UI is automatically defined...
Read more >Vaadin 14 | PDF | Java Virtual Machine - Scribd
learn Java with Vaadin as it is with any other UI framework. ... as showing a custom message when the application is not...
Read more >Book of Vaadin - DOKUMEN.PUB
learn Java with Vaadin as it is with any other UI framework. ... as showing a custom message when the application is not....
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
What should I do in generic cases where the logic that wants to do the changing doesn’t know whether things happen during navigation or not?
Also, how is the developer supposed to know that they should use another method instead? Could we make
navigate()
throw with a helpful exception instead of silently doing the wrong thing?@ayash You can use one of the
rerouteTo
methods in thebeforeEvent
instance that is passed tosetParameter
.