我有以下课程:
// The "backing bean" for DashboardDisplay.ui.xml (which is omitted for brevity).
public class DashboardDisplay extends Composite implements AcceptsOneWidget {
private EventBus eventBus;
private PlaceController placeController;
private IsWidget content = null;
public DashboardDisplay(EventBus eventBus, PlaceController placeController) {
super();
setEventBus(eventBus);
setPlaceController(placeController);
}
// Getters and setters for all properties
// ...
@Override
public void setWidget(IsWidget widget) {
setContent(widget);
}
}
public class DashboardActivity extends AbstractActivity {
private AcceptsOneWidget container;
private ActivityManager manager;
private DashboardDisplay display;
public DashboardActivity(AcceptsOneWidget container, ActivityManager manager,
DashboardDisplay display) {
super();
setContainer(container);
setManager(manager);
setDisplay(display);
// I *believe* this ensures that the 'panel' passed in to the
// start method is always our 'container'. Yes?
manager.setDisplay(container);
}
// Getters and setters for all properties
// ...
@Override
public void start(AcceptsOneWidget panel, EventBus eventBus) {
display.setEventBus(eventBus);
panel.setWidget(display);
}
}
public class DashboardActivityMapper implements ActivityMapper {
private DashboardActivity activity = null;
// Getters and setter for activity.
@Override
public Activity getActivity(Place place) {
// Leaving arguments null because I'm confused about the object graph
// (read below).
return new DashboardActivity(null, null, null);
}
}
所以我开始对于活动框架有一些相似之处,但是当我试图冒险离开 Hello,GWT 例如,我几乎立即遇到了API的障碍。
在我的应用程序的主要GWT模块MyWebAppModule
中,我正在尝试实例化和配置这3个对象。但是因为我仍然不确定如何使用他们的API,我遇到了实施问题:
public class MyWebAppModule implements EntryPoint {
@Override
public void onModuleLoad() {
// I'll worry about DI and getting GIN to work after
// I figure this basic stuff out.
EventBus eventBus = new SimpleEventBus();
PlaceController placeController = new PlaceController(eventBus);
MyWebAppPlaceHistoryMapper placeMapper = new MyWebAppPlaceHistoryMapper();
HomePlace homePlace = new HomePlace();
// WHERE THE PROBLEM STARTS
DashboardActivityMapper activityMapper = new DashboardActivityMapper();
ActivityManager manager = new ActivityManager(activityMapper, eventBus);
// Really not sure how to inject/configure this properly.
DashboardActivity dashboardActivity = new DashboardActivity(null, null, null);
// WHERE THE PROBLEM ENDS
PlaceHistoryHandler historian = new PlaceHistoryHandler(placeMapper);
historian.register(placeController, eventBus, homePlace);
historian.handleCurrentHistory();
}
}
DashboardActivityMapper
和DashboardActivity
,因此当我尝试在MyWebAppModule#onModuleLoad
内实例化并连接其实例时,会导致问题。有人可以帮我正确实现吗?一旦我得到一个工作示例,我相信我将能够连接活动框架中的其余“点”。ActivityManager manager
似乎没有被添加到任何其他类中。它是否正确? GWT是否会确保它在内存中保持活跃状态,以便它始终在eventBus
监听我为PlaceChangeEvent
传递它?或者我需要添加/注册它吗?提前致谢!
答案 0 :(得分:0)
您的DashboardActivityMapper
负责在到达指定地点(例如DashboardActivity
)时创建并返回HomePlace
。这是您缺少的信息吗?
请参阅https://developers.google.com/web-toolkit/doc/latest/DevGuideMvpActivitiesAndPlaces#ActivityMapper
只要EventBus
具有ActivityManager
的句柄(因此它可以向其发送事件)。但是,当使用非空值调用ActivityManager
时,EventBus
会在其setDisplay
方法中注册null
(并在setDisplay
传递给{时自行取消注册{1}}),并且您不会调用setDisplay
(这意味着甚至不会显示活动)