当我捕获一个异常时,我试图显示一个GWT对话框事件处理程序。对话框不显示。我已经确认了这件事调用处理程序是因为
Window.alert("some msg")
显示。当我在View对象的事件处理程序外部创建对话框时,它确实会显示。我假设对话框无法访问当前显示。有办法把这个显示出来吗?
下面是一个代码片段:eventBus.addHandler(ProcessingExceptionEvent.TYPE, new ProcessingExceptionEventHandler() {
public void onProcessingException(ProcessingExceptionEvent event) {
// Window.alert("some msg");
final WiseAlertPanel errorAlert = new WiseAlertPanel("ERROR MESSAGE: " + event.getMessage());
errorAlert.autoPositionAndShow();
}
});
public class WiseAlertPanel extends DialogBox {
VerticalPanel vpPopupl = new VerticalPanel();
public WiseAlertPanel(String text) {
setGlassEnabled(true);
Button button = new Button("Close");
button.addClickHandler(new ClickHandler() {
public void onClick(ClickEvent event) {
WiseAlertPanel.this.hide();
}
});
HorizontalPanel hPanel = new HorizontalPanel();
hPanel.setHorizontalAlignment(HasHorizontalAlignment.ALIGN_RIGHT);
hPanel.add(button);
TextArea label = new TextArea();
label.setText(text);
label.setReadOnly(true);
label.setVisibleLines(5);
vpPopupl.add(label);
vpPopupl.add(hPanel);
setWidget(vpPopupl);
}
public void autoPositionAndShow() {
setPopupPositionAndShow(new PopupPanel.PositionCallback() {
public void setPosition(int offsetWidth, int offsetHeight) {
int left = (Window.getClientWidth() - offsetWidth) / 3;
int top = (Window.getClientHeight() - offsetHeight) / 3;
WiseAlertPanel.this.setPopupPosition(left, top);
}
});
}
看起来你刚刚在内存中创建了对话框"WiseAlertPanel errorAlert"。
尝试像下面这样调用"autoPositionAndShow"中的show方法
public void autoPositionAndShow() {
setPopupPositionAndShow(new PopupPanel.PositionCallback() {
public void setPosition(int offsetWidth, int offsetHeight) {
int left = (Window.getClientWidth() - offsetWidth) / 3;
int top = (Window.getClientHeight() - offsetHeight) / 3;
WiseAlertPanel.this.setPopupPosition(left, top);
show();
}
});
}
参考GWT对话框show()