我有一个小部件(Main.java),它封装了功能并实现了用于代码拆分的异步提供程序模式。此外,我使用预取模式,以便浏览器在加载欢迎屏幕后立即下载代码。
问题出现在 IE8 中。如果我使用 Main 小部件而不进行预取,一切都很好。但是,如果我先预取然后尝试使用主小部件,则浏览器仅显示主小部件使用的 DockLayoutPanel 的中心面板。在 Firefox 中一切正常。
这是代码:
//BugTest.java
package com.bugtest.clearadd.client;
import com.google.gwt.core.client.EntryPoint;
import com.google.gwt.event.dom.client.ClickEvent;
import com.google.gwt.event.dom.client.ClickHandler;
import com.google.gwt.user.client.rpc.AsyncCallback;
import com.google.gwt.user.client.ui.Button;
import com.google.gwt.user.client.ui.FlowPanel;
import com.google.gwt.user.client.ui.Label;
import com.google.gwt.user.client.ui.PopupPanel;
import com.google.gwt.user.client.ui.RootLayoutPanel;
import com.google.gwt.user.client.ui.RootPanel;
public class BugTest implements EntryPoint {
@Override
public void onModuleLoad() {
Button prefetchButton = new Button("Prefetch!");
prefetchButton.addClickHandler(new ClickHandler() {
@Override
public void onClick(ClickEvent event) {
Main.getInstance(new AsyncCallback<Main>() {
@Override
public void onSuccess(Main result) {
PopupPanel popupPanel = new PopupPanel(true);
popupPanel
.setWidget(new Label("Prefetching finished!"));
popupPanel.center();
}
@Override
public void onFailure(Throwable caught) {
// TODO Auto-generated method stub
}
});
}
});
Button switchButton = new Button("Switch!");
switchButton.addClickHandler(new ClickHandler() {
@Override
public void onClick(ClickEvent event) {
Main.getInstance(new AsyncCallback<Main>() {
@Override
public void onSuccess(Main result) {
RootPanel.get().clear();
RootLayoutPanel.get().add(result);
}
@Override
public void onFailure(Throwable caught) {
// TODO Auto-generated method stub
}
});
}
});
FlowPanel flowPanel = new FlowPanel();
flowPanel.add(new Label("Bug test!"));
flowPanel.add(prefetchButton);
flowPanel.add(switchButton);
RootPanel.get().add(flowPanel);
}
}
//Main.java
package com.bugtest.clearadd.client;
import com.google.gwt.core.client.GWT;
import com.google.gwt.core.client.RunAsyncCallback;
import com.google.gwt.dom.client.Style.Unit;
import com.google.gwt.user.client.rpc.AsyncCallback;
import com.google.gwt.user.client.ui.DockLayoutPanel;
import com.google.gwt.user.client.ui.Label;
import com.google.gwt.user.client.ui.ResizeComposite;
public class Main extends ResizeComposite {
private static Main instance = null;
public static void getInstance(final AsyncCallback<Main> callback) {
GWT.runAsync(new RunAsyncCallback() {
@Override
public void onSuccess() {
if (instance == null) {
instance = new Main();
}
callback.onSuccess(instance);
}
@Override
public void onFailure(Throwable reason) {
callback.onFailure(reason);
}
});
}
private Main() {
DockLayoutPanel dockLayoutPanel = new DockLayoutPanel(Unit.EM);
dockLayoutPanel.addNorth(new Label("North!"), 7);
dockLayoutPanel.addWest(new Label("West!"), 15);
dockLayoutPanel.add(new Label("Center! :D"));
initWidget(dockLayoutPanel);
}
}
有谁知道它可能是什么?提前致谢。
编辑:我注意到如果我将 DockLayoutPanel 单位更改为 PX,一切正常。是错误还是我遗漏了什么?再次感谢。:P