views:

48

answers:

4

Please give me idea about the management of data in GWT. I am using Gwt in my travel portal project and my web pages is related to previous page data but when i press the refresh button of browser's then my data is lost . so please inform me if there is any way to manage this problem.

A: 

The basic idea is to store some state in the URL fragment (the part of the URL after the #) -- for example your-site.com/app#page-1

To listen for changes to the fragment, use GWT's History class. The fragment will change when the user goes back/forward, or refreshes the page.

So you could have your app do different things when the URL has #page-1 vs #page-2, etc.

A more generalized and scalable solution to this is something like gwt-platform's Place architecture (along with Presenters, which are also a good idea for large apps)

Jason Hall
+1  A: 

GWT History class cannot be used to manage page refresh (only back/forward).

A click on the refresh button send a request to the server and the state of the application is reloaded from the server. That's all. You have to deal with it.

If you don't want to lose your data, you have to find a way to save it on the server when it's needed.

A.Chatellier
+1  A: 

If your users have modern browsers, you can use the HTML5 feature localStorage to store the data in the browser between page-refresh.

Check this thread for supported browser.

pathed
+1  A: 

You can create a url fragment to encode your data.

String location = "ny"; History.newItem("location="+location);

will result with a url fragment of www.example.com#location=ny

Then if the browser is refreshed, you can decode the url fragment and determine that the location is ny.

For multiple parameters you can create a complex fragment and parse it.

History.newItem("start="+startLocation+"&end="+endLocation); Then the url would look like www.example.com#start=newyork&end=boston

nick