tags:

views:

33

answers:

1

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

+3  A: 

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.

Jason Hall
@Jason Hall - Great Jason, I didn't know that. So, in order to make this work, I need to insert a # to my URL when it is first loaded?
cinqoTimo
Not when it's first loaded - whenever you want to add/change something in the url. For an example, see how GMail changes its URL according to state changes.
Igor Klimer
Igor is correct. Though you *could* load the page with #foo=bar and handle this when your GWT code loads, if you want it to be loaded in that state. But you should make sure your bare #-less URL still works.
Jason Hall
Google also encourages you to use History as a good practice.Literally, when you need a page refresh, you move the user to a NEW PLACE.
houman001