February 18, 2009

GWT: Adding History Support

There is one very simple yet important rule for those who want to add History support to the GWT web-site:

If pressing on your UI element should result in changing the visible screen content, then the event which triggers by the UI element (i.e. onClick) should simply add new item to the History stack and exit.

If you wonder where would be the code that actually changes the screen content, I will answer, "In the HistoryListener#onHistoryChanged method." And this method will be triggered as soon as the history item will be created. If you adhere to the above rule, you will get the following benefits:
  1. You will provide the possibility to store bookmarks for specific state of your web-site
  2. You will not duplicate the logic that changes page content: all such code will go to the onHistoryChanged method

Links:
Introduction to the GWT History mechanism



http://www.linkedin.com/in/oldbam

No comments: