0

我正在创建一个具有单个入口点类的多模块项目,但有一些问题,

我有 2 个模块:-

这是我的主要模块,

@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());
    }
}

并创建了一个子模块,

public interface MyChildModule extends Mvp4gModule {
}

我的基本 eventBus 是,

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

子事件总线是,

@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 在 MyMainModule 中,而 ContentBodyPresenter、ContentBodyView 来自 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");
            }
        });
}

上面的 Presenter 访问 BaseEventBus 和 ContentBodyPresenter 如下,

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

getErrorBtn().addClickHandler(new ClickHandler() {

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

在这里,如果我访问 eventbus,如果我在上面指定了 MyChildEventBus,它仍然会访问 BaseEventBus 事件。为什么会这样。?

我继承了 MyMainModule 的 gwt.xml 中的 MyChildModule,

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

如果我编译这个项目,我会收到MyChildModule 的延迟绑定错误,并且控制台显示Method getContentBody: No instance of client.MyChildModule is defined。您是否忘记将其添加到事件总线接口的 @ChildModules 中?. 可能是什么问题。?上述代码中是否存在任何结构缺陷。?

4

1 回答 1

0

查看您发布的代码,有两件事不是必需的:

  1. 无需使用 @ChildModule 注释您的入口点。此注释在您的 BaseEventBus 类中使用。

  2. 您不需要在您的模块描述符中继承 mvp4g 子模块。Mvp4g 的模块不依赖于 GWT 模块。这是完全不同的东西。

  3. 更改@Event(generate = ContentBodyPresenter.class)@Event(handlers = ContentBodyPresenter.class)

于 2016-06-02T18:28:33.963 回答