Thursday, August 11, 2011

Add UIBinder widget to root panel

This page from the GWT doc is very helpful for getting start with UIBinder.

And they give this example for adding your UIBinder object to your application:

Document.get().getBody().appendChild(helloWorld.getElement());

Maybe that's OK for an HTML UIBinder. I haven't tried that.

Instead, I was using GWT widgets in my UIBinder, and I wanted to add a ClickHandler to one of my buttons. But nothing ever happened when I clicked it. Turns out, as I read on Stack Overflow, that indeed the handlers aren't initialized properly unless you add to the root panel.

So here's what I did that worked just fine:

RootPanel.get().add(helloWorld);

Thanks, Hilbrand!

No comments: