开发者

GWT DialogBox never shows - help

I had wrote a test composite + entry point which are just to show my test DialogBox. The structure is...

event listener code like a...

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?

Any useful comment is appreciated


First try adding Window.alert("Handler called!"); in your Button's clickHandler to see the handler actually is being called. If you see a javascript alert dialog(handler is called) that means the problem is in your 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.

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). 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 :

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


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.get().add(b);

Another reason is that you do not seem to call the .show method on the dialog:

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(). Would that help?

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜