在eventHandler中显示GWT DialogBox

时间:2016-08-31 14:58:53

标签: gwt dialog eventhandler

当我通过a捕获异常时,我正在尝试显示GWT DialogBox 事件处理程序DialogBox不显示。我已经确认了这件事 调用handler是因为

Window.alert("some msg") 

确实显示。当我在View对象的事件处理程序之外创建DialogBox时,它会显示。我假设DialogBox无法访问当前显示。有没有办法让它显示出来?

以下是代码段:

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

1 个答案:

答案 0 :(得分:0)

看起来你刚刚创建了DialogBox" 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 DialogBox show()