Skip to content

Instantly share code, notes, and snippets.

@cancerberoSgx
Created March 14, 2013 18:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save cancerberoSgx/5163720 to your computer and use it in GitHub Desktop.
Save cancerberoSgx/5163720 to your computer and use it in GitHub Desktop.
a simple UIBinder widget contains an html element with an id. AFTER calling initWidget(uiBinder.createAndBindUi(this)); document.getElementById() will return null. Only in an attach event listener I can retrieve the element by id. In the example I instantiate the widget directly from the entry point using RootPanel.get().add(new MainPanel())
package org.sgx.raphael4gwt.raphy.test.app;
public class MainPanel extends Composite {
private static MainPanelUiBinder uiBinder = GWT.create(MainPanelUiBinder.class);
interface MainPanelUiBinder extends UiBinder<Widget, MainPanel> {
}
public MainPanel() {
initWidget(uiBinder.createAndBindUi(this));
Window.alert(Document.get().getElementById("chart1")); //null
addAttachHandler(new AttachEvent.Handler() {
@Override
public void onAttachOrDetach(AttachEvent event) {
Window.alert(Document.get().getElementById("chart1")+""); //not null
}
});
}
}
<!DOCTYPE ui:UiBinder SYSTEM "http://dl.google.com/gwt/DTD/xhtml.ent">
<ui:UiBinder xmlns:ui="urn:ui:com.google.gwt.uibinder" xmlns:g="urn:import:com.google.gwt.user.client.ui">
<g:HTMLPanel>
<div id="chart1"></div>
</g:HTMLPanel>
</ui:UiBinder>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment