【发布时间】:2012-11-23 18:01:50
【问题描述】:
我已经实现了一个简单的 GWT 应用程序,它使用 1 个地方和 1 个活动(我已经将其实现为一个演示者,它扩展了一个 AbstractActivity 并包含一个 Composite“视图”子类)。视图中的第一个也是唯一的 UI 对象是 GWT-Bootstrap NavBar,我希望将其显示在“主页”的最顶部。
我在 Eclipse 内部本地运行应用程序,没有收到任何编译器或运行时错误。当我转到 Development Mode 控制台指向的 URL 时,我在浏览器中稍作停顿(我假设这是浏览器“下载”JavaScript),然后我看到一个空白屏幕(而不是我的导航栏)。窗口标题是正确的(我在模块的 HTML 页面中设置了这个),当我查看源代码时,我看到了相同的 HTML 源代码,所以我知道应用程序的 JavaScript 正在正确地进入浏览器。它只是不渲染 NavBar。
我在整个onModuleLoad() 中添加了System.out.println() 语句,我的默认ActivityManager、ActivityMapper、PlaceHistoryMapper、演示者和视图Composite,所有这些sysout 语句都打印在开发控制台中;告诉我我已将所有内容正确连接在一起,并且在运行时调用PlaceHistoryHandler#handleCurrentHistory 方法时(从onModuleLoad 内部),我应该会看到我的导航栏。
我能想到的唯一可能是:
- 我的
gwt-bootstrap配置错误;或 - 我没有正确使用 UiBinder
- 我使用“活动”和“地点”的方式有其他问题,或者我如何将 UI 附加到
RootLayoutPanel内的onModuleLoad()有问题。
至于gwt-bootstrap:
- 我将 JAR 放在项目的类路径中(我知道这一点,因为当我在小部件/视图中包含
NavBar类型的新UiField时,我没有收到任何编译器错误) - 我将
<inherits name="com.github.gwtbootstrap.Bootstrap"/>添加到我的 GWT 模块 XML 中
所以如果我还有什么需要配置的,请告诉我!
至于 UiBinder 的东西,这是我的小部件/视图:
public class WebRootDisplay extends BaseDisplay {
private static WebRootDisplayUiBinder uiBinder = GWT
.create(WebRootDisplayUiBinder.class);
interface WebRootDisplayUiBinder extends UiBinder<Widget, WebRootDisplay> {
}
@UiField
Navbar navBar;
public WebRootDisplay(EventBus eventBus) {
super(eventBus);
System.out.println("I get this printing to the console at runtime.");
initWidget(uiBinder.createAndBindUi(this));
System.out.println("...and this too!");
}
}
<!DOCTYPE ui:UiBinder SYSTEM "http://dl.google.com/gwt/DTD/xhtml.ent">
<ui:UiBinder xmlns:ui="urn:ui:com.google.gwt.uibinder"
xmlns:g="urn:import:com.google.gwt.user.client.ui"
xmlns:b="urn:import:com.github.gwtbootstrap.client.ui">
<g:HTMLPanel>
<b:Navbar ui:field="navBar">
<b:Nav>
<b:NavLink href="http://www.google.com">
Home
</b:NavLink>
</b:Nav>
</b:Navbar>
</g:HTMLPanel>
</ui:UiBinder>
我注意到我的NavBar 在UiBinder XML 中的HTMLPanel 中。我这样做是因为我使用 Google-Eclipse 插件为我生成了一个新的 UiBinder(它自动生成了 Composite(然后我对其进行了修改以扩展 BaseDisplay,它本身扩展了 Composite)以及 UiBinder sn -p. 我想 GWT 想让我把所有的 UI 字段都放在这个 HTMLPanel...(?)
如果我在这里遗漏了什么,请告诉我。我没有实例化 NavBar 字段,因为我相信这就是 createAndBindUi 为我所做的。
如果我的gwt-bootstrap 配置和我对 UiBinder 的使用看起来都是正确的,那么显然还有其他问题,我将不得不发布更多代码。我只是想在前两项被排除之前先推迟一下。提前致谢!
更新
这里是onModuleLoad:
public void onModuleLoad() {
// Some homegrown DI stuff. I have verified that the injector works properly.
ApplicationScope appScope = new ApplicationScope();
setInjector(new ApplicationInjector(appScope,
InjectorProvider.newMasterProvider()));
// Add the sole composite child to the RootLayoutPanel.
// I have verified that injectWebRootDisplay returns a fully configured
// WebRootDisplay instance.
RootLayoutPanel.get().add(injector.injectWebRootDisplay());
historyHandler.register(placeController, eventBus, defaultPlace);
historyHandler.handleCurrentHistory();
}
【问题讨论】: