Search code examples
javagwtwindowrefresh

JAVA gwt - saving info after refreshing page


At the moment , im working with java gwt and i stopped studdenly because one problem occured. I want that my information (for example string) will save after refresh button is clicked.

    // user enters something in TextArea textArea1 object

    Window.addWindowClosingHandler(new Window.ClosingHandler() {
                    public void onWindowClosing(Window.ClosingEvent closingEvent) {
                   //maybe there is a function or what                      
                   pleaseSaveInfomation(textArea1);
                    }
                });

I tried this , but i know how to implement it correctly to my source code: https://stackoverflow.com/a/14220746/5010218

The last(worst) chance is to store data from textArea in file.txt , after refreshing i could read info from file and thats all. But maybe GWT has a specific handler/method/class or what to handle this.

Thats for your opinion and help.


Solution

  • I had the same problem. You can easily overcome it with this.

    import com.google.gwt.storage.client.Storage;
      private Storage stockStore = null;
      stockStore = Storage.getLocalStorageIfSupported();
    

    Please read documentation

    http://www.gwtproject.org/doc/latest/DevGuideHtml5Storage.html#UsingStorage