Gwt uibinder sets a unique identifier

I am trying to set a unique identifier for uibinder widget.but fail.my constructor looks 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
}
+3
source share
1 answer

This works 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>

widget:

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

This produces type inference gwt-uid-#, where # is an arbitrary number.

Is the rest of your code working? It often happened that I had a typo or the like in a file ui.xmlthat did not cause visible errors (i.e. No stacktrace), but still was erroneous.

+5
source

Source: https://habr.com/ru/post/1776691/


All Articles