question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

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:open
  • Created 5 years ago
  • Comments:5 (4 by maintainers)

github_iconTop GitHub Comments

8reactions
Legiothcommented, May 9, 2018

To change the navigation target during the navigation, you should use the rerouting feature,

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?

1reaction
Legiothcommented, Aug 15, 2018

@ayash You can use one of the rerouteTo methods in the beforeEvent instance that is passed to setParameter.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found