Reputation: 794
I really doesnt understand what the PlaceTokenizer is doing? does he convert the class name of a place into a string so that the gwt history mechanism can use it to put it into the browsers url? thats what i understand but iam not sure if this is right.
Upvotes: 2
Views: 1359
Reputation: 64541
First, PlaceTokenizer
is only used in combination with the generator for PlaceHistoryMapper
(i.e. if you GWT.create()
an interface that extends PlaceHistoryMapper
; you're free to instead implement that interface in a concrete class if you prefer). The generator forces the history tokens (the part after the #
in the URL) to be composed of a prefix and a place token. The prefix is used to match with a given PlaceTokenizer
type, and is either given by the @Prefix
annotation on the tokenizer or it defaults to the simple name of the place handled by the tokenizer.
When parsing a history token (when handleCurrentHistory()
is called at initialization time, or when you navigate using your browser's history), after the prefix has been matched to a PlaceTokenizer
and an instance of that tokenizer has been retrieved (from the factory if using a PlaceHistoryMapperWithFactory
, or created using its default zero-arg constructor), the place token is passed to the getPlace
method and the tokenizer is expected to instantiate a place corresponding with the place token.
When serializing a place (when you navigate through PlaceController#goTo(Place)
in the app), a tokenizer is retrieved based on the type of the place (matched against the generic parameter of the tokenizer) and the place is given to getToken
, which is expected to return a place token for the place. The PlaceHistoryHandler
will then prepend the prefix and update the URL.
The place token can be anything, but is based on the data contained by the place (its fields), not its type (this is reflected as the prefix of the history token)
Upvotes: 5