tpow
tpow

Reputation: 7884

Updating URL without refresh

I am iterating through data and generating parameterized URL's for links (to the same page, but with parameters) on a dashboard app. However, the way I'm doing it requires a page refresh when the user clicks the link.

Generating URL with a StringBuilder

Detailhtml.append("<a href=\"http://" + domain + "&service=" + count +"&day=" + day +"\"><img src=\"/info.jpg\" alt=\"Info\"/>");

Is there a way I can dynamically create GWT buttons, or trigger some javascript to add the parameters without a page refresh?

Any help would be great...

Upvotes: 4

Views: 2709

Answers (1)

Jason Hall
Jason Hall

Reputation: 20920

The page will refresh if any part of the URL before the fragment (#) changes. So if you go form foo.com#a to foo.com/?bar=baz#a, a page refresh will be triggered.

The best way to get around this is just to never change anything before the fragment. Change foo.com/?bar=baz to foo.com/#bar=baz (or some variant) and have your GWT app listen for History changes by calling History.addHistoryListener(...).

Then, when you hear a history change, parse the fragment in the URL and update your app accordingly.

Some libraries like gwt-platform provide a wrapper around this functionality and let you describe Places which will get triggered when the fragment updates to match them. If you end up doing a lot of complicated things with the fragment, it would be a good idea to look into places. But if you're just passing a few parameters around, you can get away with just listening for History changes.

Upvotes: 5

Related Questions