Issues with EventBus and Gin in Gwt 2.4

I am trying to use Gin in MVP GWT 2.4. In my module, I have:

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

The code above uses the new com.google.web.bindery.event.shared.EventBus . The problem occurs when I want to enter the event bus in the MVP Activities that implement the Activity:

 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 uses the deprecated com.google.gwt.event.shared.EventBus . How can I reconcile them? Obviously, if I ask for an obsolete EventBus type, then Jin will complain because I did not specify a binding for him.

Refresh . This will allow you to create an application, but now there are two different EventBus s, which is terrible:

  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
source share
4 answers

There is a current problem for this: http://code.google.com/p/google-web-toolkit/issues/detail?id=6653

Recommended work, unfortunately, is simply sticking to an outdated EventBus in your code.

+2
source

I asked a similar question: Which GWT EventBus should I use?

You do not need an obsolete event bus, as it extends WebBindery.

Create a base. The actions that your actions propagate with this code:

 // 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); 
+2
source

I think this is a cleaner solution:

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

Please refer to my answer here

+1
source

I found that linking both the new and the old versions to the same instance helps.

  /* * 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); 

Now that your code needs an EventBus , enter the one you need for the code and avoid the failure warnings.

0
source

Source: https://habr.com/ru/post/1396279/


All Articles