为什么我需要覆盖“onPlaceRequest”在每个演示者课程中?
我通过 Places 管理项目中的历史记录。
我所做的是:
- 在顶层实现 PlaceRequestHandler (例如 AppController),
- 注册它 -> eventBus.addHandler(PlaceRequestEvent.getType(), this);
- 实现方法“onPlaceRequest”,我在其中进行项目导航。
我正在使用 GWT 演示器,项目中的每个演示器都会重写 onPlaceRequest
方法。
当每个请求都是从顶级“onPlaceRequest”方法处理时,为什么我需要这个?
我将举一个例子:
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
}
让我们以一位演示者为例
public class SomePresenter extends Presenter<SomePresenter.Display>
{
... here some methods are overriden and
@Override
protected void onPlaceRequest(PlaceRequest request)
{
// what should I do here?
}
}
,这个想法是什么,以及我应该如何做使用它吗?
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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以将
PlaceHistoryHandler
和PlaceController
附加到事件总线,而不是让所有演示者扩展PlaceRequestHandler
并自己管理这些事件。它们共同为您管理浏览器的历史记录和位置。当您要求PlaceController
goTo() 到另一个地点时,它将停止您当前的活动并使用地点到活动(您的演示者)的映射来选择下一个开始的活动。要使用此技术,您需要让演示者扩展
AbstractActivity
。尝试按照 GWT 文档中的 Google 教程进行操作,名为使用 Activity 和 Places 进行 GWT 开发。Instead of making all of your presenters extend
PlaceRequestHandler
and managing those events yourself, you can attach aPlaceHistoryHandler
and aPlaceController
to your event bus. Together, they manage the browser's history and your places for you. When you ask yourPlaceController
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.