How to implement GWT PlaceHistoryMapper using custom tokens?

I want my little GWT application to have all of the following "bookmarkable" Place s:

 http://www.mywebapp.com --> "home page" http://www.mywebapp.com/login --> login screen http://www.mywebapp.com/main --> main menu, after logged in http://www.mywebapp.com/start --> start of a transactional process http://www.mywebapp.com/complete --> end of transactional process (receipt) 

So, I went ahead and created 5 Place subclasses, all of which are as follows:

 public class LoginPlace extends Place { // Intentionally left void because I'm not sure // what to implement here... } 

And they have corresponding tokenizers:

 public class LoginPlaceTokenizer extends PlaceTokenizer<LoginPlace> { @Override public LoginPlace getPlace(String token) { // ??? } @Override public String getToken(LoginPlace place) { // ??? } } 

I am trying to implement PlaceHistoryMapper for my application:

 @WithTokenizers({ HomePlaceTokenizer.class, LoginPlaceTokenizer.class, MainMenuPlaceTokenizer.class // etc. }) public class MyWebAppPlaceHistoryMapper implements PlaceHistoryMapper { @Override public Place getPlace(String token) { // ??? } @Override public String getToken(Place place) { // ??? } } 

The companion getPlace / getToken in subclasses of PlaceTokenizer<T> and in MyWebAppPlaceHistoryMapper seem to do the same. Are they? If so, am I just using the same code inside them? If they do not match, how do they differ from each other and how to implement them?

Keep in mind the URL markers that I want as bookmarks in the application - I do not want to use the default GWT markers someDisplay:SomePlace . Thanks in advance!

+4
source share
1 answer

Either you use the interface annotated with @WithTokenizers and GWT generates an implementation from GWT.create(MyWebAppPlaceHistoryMapper.class) , or you implement the PlaceHistoryMapper interface manually and you do not need PlaceTokenizer s.

Using GWT.create() GWT implements the getPlace and getToken for sending to the appropriate PlaceTokenizer depending on the token prefix (using the if…else cascade with prefix.equals(...) based on @Prefix annotations on PlaceTokenizer s) or type Place (using the if…else cascade with instanceof based on the general type of PlaceTokenizer s).

+4
source

Source: https://habr.com/ru/post/1444793/


All Articles