简体   繁体   English

GWT 对话框从不显示 - 帮助

[英]GWT DialogBox never shows - help

I had wrote a test composite + entry point which are just to show my test DialogBox.我写了一个测试复合+入口点,只是为了显示我的测试对话框。 The structure is...结构是...

  • A) EntryPoint contains Composite A)EntryPoint 包含 Composite
  • B) Composite contains Button (in ScrollPanel) to show A class B)复合包含按钮(在 ScrollPanel 中)以显示 A class
  • C) A class extends DialogBox C) A class 扩展对话框

event listener code like a...事件监听器代码就像...

button.addClickHandler(new ClickHandler() { public void onClick(ClickEvent event) { DialogBox aDialog=new A(); aDialog.center(); aDialog.show(); } }); button.addClickHandler(new ClickHandler() { public void onClick(ClickEvent event) { DialogBox aDialog=new A(); aDialog.center(); aDialog.show(); } });

No doalogBox ever shown:( What am I doing wrong?没有显示任何doalogBox:(我做错了什么?

Any useful comment is appreciated任何有用的评论表示赞赏

First try adding Window.alert("Handler called;");首先尝试添加Window.alert("Handler called;"); in your Button's clickHandler to see the handler actually is being called.在您的 Button 的 clickHandler 中查看处理程序实际上正在被调用。 If you see a javascript alert dialog(handler is called) that means the problem is in your CustomDialogBox.如果您看到 javascript 警报对话框(调用了处理程序),则表示问题出在您的 CustomDialogBox 中。 Make sure you set the content of your dialog box by setWidget(Widget w) BEFORE you call show() to make it visible otherwise it won't show.确保在调用show() )之前通过setWidget(Widget w)设置对话框的内容以使其可见,否则不会显示。

If no alert(handler is never called) that means the problem lies within your composite.如果没有警报(从不调用处理程序),则意味着问题出在您的复合材料中。 It can be an issue of adding some of the elements directly to DOM without using widgets, it would break the gwt even mechanism(would explain why it works when you add button to root panel).在不使用小部件的情况下直接将一些元素添加到 DOM 可能是一个问题,它会破坏 gwt 偶数机制(将解释为什么当您将按钮添加到根面板时它会起作用)。 Other than that, it is hard to tell without seeing some code.除此之外,如果不看一些代码就很难判断。

Lastly I will post some working code in case you decide to work your way up from this to see where it fails.最后,我将发布一些工作代码,以防你决定从这里开始,看看它在哪里失败。 Here is a code that works:这是一个有效的代码:

First Extend DialogBox (dont forget to set its widget):首先扩展对话框(不要忘记设置它的小部件):

public class CustomDialog extends DialogBox {
    public CustomDialog() {
        setWidget(new Label("Hello!"));
    }
}

Then build a composite:然后构建一个复合:

public CustomComposite() {
    Button b = new Button("Pop it up");
    b.addClickHandler(new ClickHandler() {
        @Override
        public void onClick(ClickEvent event) {
            new CustomDialog().show();
        }
    });
    initWidget(b);
}

finally onModuleLoad:最后 onModuleLoad:

public void onModuleLoad() {
    CustomComposite c = new CustomComposite();
    RootPanel.get().add(c);
}

BTW: center() does center the pop up and then show() s, so you don't need to call both顺便说一句: center()确实将弹出窗口居中,然后是show() s,因此您不需要同时调用两者

One possible reason is that you are not adding anything to the RootPanel, inwhichcase you are creating the DOM structure in memory but you are not attaching it to anything:一个可能的原因是您没有向 RootPanel 添加任何内容,在这种情况下,您正在 memory 中创建 DOM 结构,但您没有将其附加到任何内容:

RootPanel.get().add(b);

Another reason is that you do not seem to call the.show method on the dialog:另一个原因是您似乎没有在对话框上调用 .show 方法:

new MyDialog().show();

There could be several reasons for the behavior you are describing, please post the complete example for a more targeted answer.您描述的行为可能有多种原因,请发布完整示例以获得更有针对性的答案。

I think I had similar problem before and what I did is calling the show() before center().我想我以前遇到过类似的问题,我所做的是在 center() 之前调用 show()。 Would that help?那会有帮助吗?

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM