4

MVP GWT 2.4 で Gin を使用しようとしています。私のモジュールには、次のものがあります。

import com.google.web.bindery.event.shared.EventBus;
import com.google.web.bindery.event.shared.SimpleEventBus;

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

上記のコードでは、新しいcom.google.web.bindery.event.shared.EventBus. アクティビティを実装する MVP アクティビティにイベント バスを挿入したい場合に問題が発生します。

package com.google.gwt.activity.shared;

import com.google.gwt.event.shared.EventBus;
import com.google.gwt.user.client.ui.AcceptsOneWidget;

public interface Activity {

  ...

  void start(AcceptsOneWidget panel, EventBus eventBus);
}

Activity非推奨の を使用しcom.google.gwt.event.shared.EventBusます。どうすれば2つを調和させることができますか? 明らかに、非推奨タイプの EventBus を要求すると、そのバインディングを指定していないため、Gin は文句を言うでしょう。

更新: これにより、アプリをビルドできるようになりますが、今では 2 つの異なるEventBuss があり、これはひどいものです:

 protected void configure() {
    bind(com.google.gwt.event.shared.EventBus.class).to(
        com.google.gwt.event.shared.SimpleEventBus.class).in(Singleton.class);
    bind(EventBus.class).to(SimpleEventBus.class).in(Singleton.class);
    ...
4

4 に答える 4

2

これについて記録された現在の問題があります: http://code.google.com/p/google-web-toolkit/issues/detail?id=6653

推奨される回避策は、残念ながらEventBus、コード内の非推奨のままにしておくことです。

于 2012-02-13T22:55:21.760 に答える
2

同様の質問をしました:どの GWT EventBus を使用すればよいですか?

WebBindery を拡張するため、非推奨のイベント バスは必要ありません。

次のコードを使用して、すべてのアクティビティを拡張するベース アクティビティを作成します。

// Forward to the web.bindery EventBus instead
@Override
@Deprecated
public void start(AcceptsOneWidget panel, com.google.gwt.event.shared.EventBus eventBus) {
   start(panel, (EventBus)eventBus);
}

public abstract void start(AcceptsOneWidget panel, EventBus eventBus);
于 2012-02-14T15:31:22.970 に答える
1

よりクリーンなソリューションはこれだと思います:

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;
    }

...

ここで私の答えを参照してください

于 2013-06-06T00:16:03.273 に答える
0

新しいバージョンと古いバージョンの両方を同じインスタンスにバインドすると役立つことがわかりました。

    /*
     * bind both versions of EventBus to the same single instance of the
     * SimpleEventBus
     */
    bind(SimpleEventBus.class).in(Singleton.class);
    bind(EventBus.class).to(SimpleEventBus.class);
    bind(com.google.gwt.event.shared.EventBus.class).to(SimpleEventBus.class);

コードが必要とするときはいつでも、コードが必要EventBusとするものを挿入し、非推奨の警告を回避します。

于 2013-01-30T17:01:53.283 に答える