Search code examples
javavaadin7

reloading page with parameter in url fragment adds extra slash character in vaadin


I am calling

getUI().getNavigator().navigateTo("myview/param=myparam");

and the Navigator opens the View registered as "myview" where the parameters can be obtained from the ViewChangeEvent by calling

event.getParameters()

which returns "param=myparam". My browser displays the url

myapp/#!myview/param=myparam

However, if I reload the page (e.g. using F5)

getUI().getNavigator().navigateTo("!myview/param=myparam");

(note the extra exclamation mark) will be called and the url changes to

myapp/#!myview//param=myparam

(note the double slash which is not supposed to be a comment), which obviously is a problem and actually every page reload adds another slash. Am I doing something wrong here or how else can this be resolved ? I am using CDIViewProvider which might be of interest.

Note: It looks like someone had a similar problem here Vaadin 7 url navigation hashbang but this does not answer my question.


Solution

  • I did not realize that when pressing F5 the UI is reloaded. There was a call like

    String uriFragment = getPage().getUriFragment();
    getUI().getNavigator().navigateTo(uriFragment);
    

    in the initialization code of my UI class. Apparently the exclamation mark is included in the return of getUriFragment(), i.e. it returns "!myview/param=myparam". I fixed this by simply stripping the exclamation mark at this point.