Question

i try to set unique id for uibinder widget.but fail .my constructor look like below

public CustomUIWidget() {



    initWidget(uiBinder.createAndBindUi(this));

     this.getWidget().getElement().setId(DOM.createUniqueId());

         System.out.println(this.getWidget().getElement().getId());  //put debug line here, value is empty
}
Was it helpful?

Solution

This is working for me (using GWT 2.1):

ui.xml:

<!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>
        <g:Label text="test" />
    </g:HTMLPanel>
</ui:UiBinder>

the widget:

public TestView() {
    initWidget(uiBinder.createAndBindUi(this));
    getWidget().getElement().setId(DOM.createUniqueId());
    System.out.println(getWidget().getElement().getId());
}

This creates an output like gwt-uid-# where # is an arbitrary number.

The rest of your code is working? It had often happened too my that I had a typo or the like in the ui.xml file that didn't produce any visible error (i.e., no stacktrace) but still was erroneous.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top