Pratik Rawlekar
Pratik Rawlekar

Reputation: 327

Deferred binding in multi-module project and issues while accessing eventBus

I am creating a multi-module project with a single entry point class but has some issues,

I have 2 modules as :-

This is my main module,

@ChildModule(moduleClass = MyChildModule.class)
public class MyMainModule implements EntryPoint {
  @Override
  public void onModuleLoad() {
    Mvp4gModule module = (Mvp4gModule) GWT.create(Mvp4gModule.class);
    module.createAndStartModule();
    RootPanel.get().add((Widget) module.getStartView());
    }
}

and created a child module as,

public interface MyChildModule extends Mvp4gModule {
}

My base eventBus is,

@Events( startPresenter = HomePresenter.class,historyOnStart=true)
@ChildModules(@ChildModule(moduleClass=MyChildModule.class, async=true, autoDisplay=false   ))
public interface BaseEventBus extends EventBusWithLookup {

@InitHistory
@Event(handlers = HomePresenter.class)
void init();

@Start
@Event(handlers = HomePresenter.class)
void start();

@Event(forwardToModules=MyChildModule.class)
void getContentBody();

@Event(handlers = HomePresenter.class)
void setContentBody(ContentBodyView contentBodyView);
}

and child event bus is,

@Events(module=MyChildModule.class, startPresenter = ContentBodyPresenter.class)
public interface MyChildEventBus extends EventBusWithLookup {


@Event(generate = ContentBodyPresenter.class)
void getContentBody(); 

@Event(forwardToParent=true)
void setContentBody(ContentBodyView contentBodyView);
}

HomePresenter, HomeView are in MyMainModule and ContentBodyPresenter,ContentBodyView are from MyChildModule.

@Presenter(view = HomeView.class)
public class HomePresenter extends BasePresenter<HomeView, BaseEventBus>{

getErrorBtn().addClickHandler(new ClickHandler() {

            @Override
            public void onClick(ClickEvent arg0) {
                eventBus.showError("Error");
            }
        });
}

the above presenter accessing BaseEventBus and ContentBodyPresenter is as followa,

@Presenter(view = ContentBodyView.class)
public class ContentBodyPresenter extends BasePresenter<ContentBodyView, MyChildEventBus>{

getErrorBtn().addClickHandler(new ClickHandler() {

        @Override
        public void onClick(ClickEvent arg0) {
            eventBus.showError("Error");
        }
    });
}

here if I access eventbus it will still accessing BaseEventBus event if I specified MyChildEventBus above. Why is it so.?

and I inherited the MyChildModule in gwt.xml of MyMainModule as,

<inherits name='abc.xyz.MyChildModule' />

If I compile this project, am getting deferred binding error for MyChildModule and console shows Method getContentBody: No instance of client.MyChildModule is defined. Have you forgotten to add it to @ChildModules of your event bus interface?. What can be the issue.? Is there any structural flaw in above code.?

Upvotes: 0

Views: 234

Answers (1)

El Hoss
El Hoss

Reputation: 3832

Looking at the code you have posted, there are two things that are not necessary:

  1. There is no need to annotate your EntryPoint with @ChildModule. This annotation is used inside your BaseEventBus class.

  2. You don't need to inherit the mvp4g child module in your modul descriptor. Mvp4g's modules does not depend on GWT modules. It's something totally different.

  3. change @Event(generate = ContentBodyPresenter.class) to @Event(handlers = ContentBodyPresenter.class)

Upvotes: 0

Related Questions