简体   繁体   中英

How to add a list of TextBox widgets to a Panel widget declared using UiBinder (GWT)?

I use UiBinder to define my page element in a sinple GWT application.

"Login.ui.xml" is defined as belows.

<ui:UiBinder xmlns:ui='urn:ui:com.google.gwt.uibinder'
    xmlns:gwt='urn:import:com.google.gwt.user.client.ui'>
<gwt:HTMLPanel>
    <div align="center">
        <gwt:VerticalPanel ui:field="myMeasuresBoxesPanel">

        </gwt:VerticalPanel>
    </div>
</gwt:HTMLPanel>

The Login class is defined as:

public class Login extends Composite {

    private static LoginUiBinder uiBinder = GWT.create(LoginUiBinder.class);

    /*
     * @UiTemplate is not mandatory but allows multiple XML templates to be used
     * for the same widget. Default file loaded will be <class-name>.ui.xml
     */
    @UiTemplate("Login.ui.xml")
    interface LoginUiBinder extends UiBinder<Widget, Login> {
    }

    @UiField
    VerticalPanel myMeasuresBoxesPanel;

    public Login() {
        this.myMeasuresBoxesPanel.getElement().setId("myMeasuresBoxesPanel");
        for(int i = 0; i < 10; i ++) {
            TextBox newMeasureTextBox = new TextBox();
            newMeasureTextBox.setText(String.valueOf(i));
            this.myMeasuresBoxesPanel.add(newMeasureTextBox);
        }

        initWidget(uiBinder.createAndBindUi(this));
    }
}

I would like the myMeasuresBoxesPanel verticalPanel to be initialized with a list of 10 TextBox widgets for user to enter info.

The code was compiled fine but the web page didn't display the textboxes but just an empty Table rendered from the verticalPanel.

I found an answer. Calling initWidget(uiBinder.createAndBindUi(this)); before adding all TextBox widgets to the panel solved the problem.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM