I'm managing the History in my project via Places.
What I do is this:
- implement PlaceRequestHandler on top level (for example AppController),
- register it -> eventBus.addHandler(PlaceRequestEvent.getType(), this);
- implement method "onPlaceRequest" ,where i do project navigation.
I'm using GWT presenter and every presenter in my project overrides the onPlaceRequest
method.
Why do I need this, when every request is handled from the top level "onPlaceRequest" method?
I will give an example:
public class AppController implements Presenter, PlaceRequestHandler
...........
public void bind()
{
eventBus.addHandler(PlaceRequestEvent.getType(), this);
...
}
public void onPlaceRequest(PlaceRequestEvent event)
{
// here is the project navigation tree
}
and let's take one presenter
public class SomePresenter extends Presenter<SomePresenter.Display>
{
... here some methods are overriden and
@Override
protected void onPlaceRequest(PlaceRequest request)
{
// what should I do here?
}
}
开发者_开发技巧What is the idea, and how I'm supposed to use it?
Instead of making all of your presenters extend PlaceRequestHandler
and managing those events yourself, you can attach a PlaceHistoryHandler
and a PlaceController
to your event bus. Together, they manage the browser's history and your places for you. When you ask your PlaceController
to goTo() a different place, it will stop your current activity and use a mapping of places to activities (your presenters) to choose which one to start next.
To use this technique, you need to have your presenters extend AbstractActivity
. Try following through Google's tutorial about it in GWT's documentation called GWT Development with Activities and Places.
精彩评论