Skip to main content

Home/ GWT - Samples/ Group items tagged sample

Rss Feed Group items tagged

Esfand S

developerlife - Tutorials » GWT Tutorial - Managing History and Hyperlinks - 0 views

  • GWT provides a way for your apps to hook into the browser’s history mechanism, so that you can control what happens when a user hits Back or Forward in their browser. You can also programmatically manipulate the browser’s history, and even create hyperlinks in your apps that can hook into the browser’s history mechanism. You can even intercept these hyperlinks when a user clicks on them, instead of having the browser handle it, or both.
  • tokens allow you to map a specific state of your application to what’s in the browser’s history stack. When your app starts up, the stack is empty. When the user interacts with your app, and clicks on something, you can add tokens to this stack (either via hyperlinks or calls to History.newItem(String token)). This lets you change the history. You can also attach a HistoryListener to your app which will allow your app to respond to this change of history.
  • Why do it this way? I mean, if your app generates the tokens themselves, why not just change the state instead of dealing with receiving a history change notification (that you just initiated) and then respond to it? A good reason for taking the trouble to do this, is to allow people to bookmark certain states of your application. If you don’t want them to do this, then you can just plug into the history mechanism, and then ignore all the history state change events, and make it so that the Back or Forward button does not mess your app up.
  • ...7 more annotations...
  • If there are tokens in the history stack, and the user presses the Back button, or you invoke the History.back() method, then the following steps occur: a token is retrieved from the top of the stack this token (which is just a String) is then passed to your HistoryListener implementation, and this is how you know that the Back button is pressed. You then have to parse that token and change the state of your application to match what this token represents to your app.
  • no matter what happens, all these Back/Forward actions (whether initiated programmatically by your app, or by a user) ends up calling your HistoryListener’s onHistoryChanged(String token) method, which can act as a traffic cop of your state machine. You are in control of defining what a token is, and how it should map to various states in your application. You can encode parameters in the token and then parse them out later, to understand what your app is supposed to do now.
  • If you noticed the change in the browser’s displayed URL, when a hyperlink with a history token is clicked, then can see how the user is able to bookmark a specific state in your app… the token is simply added to the URL in the browser prefixed with a “#”. So, is it possible to add your own history token by typing in the URL for your app and just appending “#mynewtoken” to it? Yes! This is how GWT handles people bookmarking specific states of your application. One thing to keep in mind is that if you end the browser session, and then come into the app, then your app will have to process the initial history state, and it will have to check to see if there is “#mynewtoken” passed in the URL to the browser, and then adjust it’s state accordingly
  • you can hook into this mechanism and make it possible for the app to go to a particular state or load a particular resource or perform a function based on what is passed as a token to the URL.
  • You can use pass parameters to your app via the URL (here’s a coding quickie that shows you how), and you can use it along with tokens, but it’s bit confusing to use both.
  • let’s use this URL as an example: http://localhost:8888/Sample.Client/index.html#link2token?p1=v1&p2=v2 When you run the app with this URL, you will get the following string as the token: “link2token?p1=v1&p2=v2“. So as you can see it’s not a great idea to mix the two. This is the kind of URL that’s generated by the GWT Hyperlink class, so you can’t really mix and match query strings with history tokens.
  • If you want to create the URL yourself, then you can pass history tokens and query strings. In order to do this, you have to make sure to place the query string (?p1=v1&p2=v2) before the “#” in the URL and it will work. If you use this URL as an example: http://localhost:8888/Sample.Client/index.html?p1=v1&p2=v2#link2token When you run the app with this URL, you will get the following string as the history token: “link2token“. And a call to GWTUtils.getParamString() will return “?p1=v1&p2=v2“.
Esfand S

Mail App - 0 views

Esfand S

My First GWT IGoogle Gadget, What do you think? - Google Web Toolkit | Google Groups - 0 views

  • I built a basic and more complex gadgets which are demoed here. More Info here: http://code.google.com/p/gwt-examples/wiki/project_Gadget?ts=12722477... Basic Gadget is released here: IGoogle Directory: http://www.google.com/ig/directory?url=demogadgetmathflashcard.appspo...
Esfand S

Tell the FCC - 0 views

1 - 20 of 130 Next › Last »
Showing 20 items per page