Change URL to trigger event in GWT

I repeat some of the data and create parameterized URLs based on the following conditions:

finishedHTML.append("<a href=\"http://" + domain + "&service=" + allEvents[eventCounter].EventService +"&day="+ offSet+(-1 * i) +"\"><img src=\"/info.jpg\" alt=\"Info\"/>"); 

I had the beginning of my application checking the parameters of the url when the page was loaded / updated, and follow some steps depending on whether the parameters were and what they were.

However, I added # to the beginning of the parameters, so there is no need to refresh the page, but now it does not start the function that checks the URL.

My question is, how can I trigger an event in GWT when a user clicks a link? Do I need to generate GWT controls and bind a click handler? Is it possible to set up an event that fires when a URL changes?

UPDATE: Adam answered part of the original question, but I cannot get querystring after "#". Is there a better way than the function below:

 public static String getQueryString() { return Window.Location.getQueryString(); } 

In other words, if I enter example.com?service=1 , I get service = 1 as my request. If I enter example.com#?service=1 , I get a null value for the request.

+4
source share
2 answers

Use History.addValueChangeHandler( handler ) and create a handler to catch URL changes.

No need for click handlers, etc., any change to the hash part in the URL will be sufficient.

EDIT:

See this sample code - it will parse the URLs of the form http://mydomain/my/path#tok1&tok2&tok3

 public void onValueChange(ValueChangeEvent<String> event) { String hash = event.getValue(); if ( hash.length() == 0 ) { return; } String[] historyTokens = hash.split("&",0); // do stuff according to tokens } 
+9
source

(just responding to your update) Have you tried

 History.getToken() 

to get the value after "#"?

+4
source

All Articles