Stefan Falk
Stefan Falk

Reputation: 25387

GWT Hyperlink strange behavior - redirecting to http://localhost:8080/#

Okay, this is very strange.

All I am having is a Hyperlink in my menu:

Hyperlink eventCalendar= new Hyperlink("Eventkalender", "eventCalendar=" + store.getId());

and I am listening to the ValueChangeEvent in the MainViewPresenter. Please notice that I am not doing anything. Right before the creation of the listener I am setting a SimplePanel to be the display for the ActivityManager:

App.activityManager.setDisplay(this.mainView.getMainContentContainer());

History.addValueChangeHandler(new ValueChangeHandler<String>() {
    @Override
    public void onValueChange(ValueChangeEvent<String> event) {
        String historyToken = event.getValue();
        GWT.log("onValueChange() historyToken " + historyToken);
    }
});

But if I click the link what happens is this:

First, for the blink of an eye I can see the browser URL change to

http://localhost:8080/#eventCalendar=1

but it changes immediately back to

http://localhost:8080/#

which causes my landing page to get loaded inside the SimplePanel which I declared as display (see above).

Does anybody have an idea what could cause this behavior because this does not make sense to me? Why does the URL get changed again? Am I using History or Hyperlink wrong?

Upvotes: 2

Views: 64

Answers (1)

Thomas Broyer
Thomas Broyer

Reputation: 64541

Most probably your PlaceHistoryMapper returns null for the eventCalendar=1 token, so it's replaced with the default place you gave to the PlaceHistoryHandler. If you're using GWT.create() based on PlaceTokenizers, with a factory and/or @WithTokenizers, that means either you don't have a PlaceTokenizer for the empty-string prefix (@Prefix("")), or that one tokenizer returns null.

That being said, you probably should rather try to use places directly rather than going through the history. That means using a ClickHandler on some widget and calling PlaceController#goTo with the appropriate place. Ideally, that widget would be an Anchor whose href is computed from the result of getToken from your PlaceHistoryMapper with the given place (how the href actually looks depends on your Historian; if you stick to the default behavior, then just prepend a # to the returned token).

Upvotes: 1

Related Questions