检查GWT EventBus是否具有EventHandler

检查GWT EventBus是否具有EventHandler,gwt,Gwt,每次使用以下行初始化视图时,我都会添加EventHandler: AGWTService.App.getEventBus().addHandler(AnEvent.TYPE, this.AClass); 这将导致应用程序生命周期中的多个事件处理。但是,没有方法从EventBus中删除处理程序或检查EventBus是否已经具有EventHandler。在我的例子中,EventBus是一个静态的SimpleEventBus类: private static final EventBus EVENT

每次使用以下行初始化视图时,我都会添加EventHandler:

AGWTService.App.getEventBus().addHandler(AnEvent.TYPE, this.AClass);
这将导致应用程序生命周期中的多个事件处理。但是,没有方法从EventBus中删除处理程序或检查EventBus是否已经具有EventHandler。在我的例子中,EventBus是一个静态的SimpleEventBus类:

private static final EventBus EVENT_BUS = GWT.create(SimpleEventBus.class);

我试图用ResettableEventBus包装EventBus,但没有帮助。在视图上处理EventBus的正确方法是什么。

addHandler()方法返回HandlerRegistration,removeHandler()方法可用于删除处理程序。

addHandler()方法返回HandlerRegistration,removeHandler()方法可用于删除处理程序。

是的,这项工作!谢谢最好提供要删除的处理程序()方法的类型,而不是一次删除所有处理程序。在调用HandlerRegistration#remove()时,只删除一个处理程序-返回HandlerRegistration对象的处理程序。忘记写入,确切的方法名为removeHandler()。对,修复了答案。是的,这项工作!谢谢最好提供要删除的处理程序()方法的类型,而不是一次删除所有处理程序。在调用HandlerRegistration#remove()时,只删除一个处理程序-返回HandlerRegistration对象的处理程序。忘记写入,确切的方法名为removeHandler()。对,修复了答案。