我应该使用哪种GWT EventBus?

时间:2012-01-20 20:53:00

标签: java gwt event-handling

在gwt-user.jar中有2个EventBus接口和SimpleEventBus implmentations。

com.google.gwt.event.shared.EventBuscom.google.web.bindery.event.shared.EventBus 我将这些称为'gwt.event'和'web.bindery'。

查看JavaDocs和源代码,我可以看到gwt.event只包含web.bindery。但是,gwt.event实现还隐藏了许多已弃用的方法

那么我应该使用哪种实现方式? (我在GWT 2.4上)

4 个答案:

答案 0 :(得分:19)

通常你应该使用com.google.web.bindery中的那个。唯一的版本曾经在com.google.gwt.event中,但是当RequestFactory和AutoBeans从GWT本身移出并进入com.google.web.bindery时,它们可以在非GWT客户端中工作。

如果您在演示者等中使用com.google.web.bindery版本,则可以在需要时更轻松地使用外部GWT应用。将该实例传递给PlaceController以及其他使用EventBus的类时,您也不会收到弃用警告。

答案 1 :(得分:4)

我知道这个问题已经有了答案,但在添加以下内容时可能值得。正如我在上面的评论中所说,Activity仍然需要com.google.gwt.event.shared.EventBus类。为了避免弃用警告,我做了以下(我使用GIN):

public class GinClientModule extends AbstractGinModule {

    @Override
    protected void configure() {
        bind(EventBus.class).to(SimpleEventBus.class).in(Singleton.class);
        ...
    }

    @Provides
    @Singleton
    public com.google.gwt.event.shared.EventBus adjustEventBus(
            EventBus busBindery) {
        return (com.google.gwt.event.shared.EventBus) busBindery;
    }

...

通过这样做,您将始终使用bindery包中“新”版本的Event总线中的对象。

答案 2 :(得分:2)

如果您使用活动,那么您可能必须使用已弃用的活动,至少在他们清理整个API之前:http://code.google.com/p/google-web-toolkit/issues/detail?id=6653

答案 3 :(得分:0)

使选择更加复杂。我在我的GWT应用程序中使用guava,谷歌人已经在那里添加了另一个EventBus(甚至功能更少)。

也许这些人需要坐在一起定义一个实现来统治它们?

显然,我想避免对GWT代码中没有严格使用的代码的GWT的所有依赖,所以Guava对我来说很有趣。

相关问题