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