有 Java 编程相关的问题?

你可以在下面搜索框中键入要查询的问题!

UiBinder中的java GWT动态复选框

如何在UiBinder中实现GWT动态复选框。 enter image description here

我的要求是:我应该实现动态复选框。标记的复选框不是固定的,可能有更多或更少的复选框。 通过使用<gwt:CheckBoxGroup ui:field="group1">,我可以用这样的静态数据实现固定复选框

                    <m:CheckBoxGroup ui:field="group2">
                        <m:CheckBox>11/17/2016</m:CheckBox>
                        <m:CheckBox>11/15/2016</m:CheckBox>
                        <m:CheckBox>11/14/2016</m:CheckBox>
                        <m:CheckBox>11/11/2016</m:CheckBox>
                    </m:CheckBoxGroup>

你能帮我在uibinding中实现动态复选框吗


共 (1) 个答案

  1. # 1 楼答案

    UiBinder只是一个声明性XML模板。在docs中,你会发现:

    It is not a renderer, or at any rate that is not its focus. There are no loops, no conditionals, no if statements in its markup, and only a very limited expression language. UiBinder allows you to lay out your user interface. It’s still up to the widgets or other controllers themselves to convert rows of data into rows of HTML.

    因此,您需要使用Java代码将复选框添加到CheckBoxGroup

    @UiField
    CheckBoxGroup group1;
    
    ...
    
    CheckBox check1 = new CheckBox();
    check1.setBoxLabel("11/17/2016");
    
    ...
    
    group1.add(check1);
    group1.add(check2);
    group1.add(check3);
    

    更多示例here