injoy
injoy

Reputation: 4373

What's the difference/relationship between history and places in GWT?

Based on my observation, the History is used in a single html page with multiple AJAX interactions. It just assigns each state to a specific token to distinguish(or mark) them. While for the Places, it's used for different html pages. It assigns each html page to a string token.

Is there any relationship between them? And do I understand correctly?

Upvotes: 2

Views: 85

Answers (1)

Igor Klimer
Igor Klimer

Reputation: 15321

As stated in the official documentation:

A place is a Java object representing a particular state of the UI. A Place can be converted to and from a URL history token (see GWT’s History mechanism) by defining a PlaceTokenizer for each Place, and GWT’s PlaceHistoryHandler automatically updates the browser URL corresponding to each Place in your app.

So you can think of Places and Activities a higher level above History. For example, you can go to a new "place" in your application by changing the history token with History.newItem("token"). But you can use PlaceController to do the same: placeController.goTo(new TokenPlace()). TokenPlace is explicitly associated with the history token token, has an Activity class instantiated when this place is reached, etc. Under the hoods, History.newItem("token") will still be called, but you don't have to worry about managing history tokens manually. As a bonus, your application will probably become less coupled, because now Activity1 doesn't have to know anything about Activity2 - Activity1 just triggers a move to a new Place. It doesn't care which activity it's associated with.

Upvotes: 5

Related Questions