GWT 中奇怪的单选按钮行为

Strange radio button behaviour in GWT

我遇到了一个与 RadioButtons 有关的奇怪案例 GWT。我的built 组件由内部的多个无线电组成,我们称之为X。默认选择X 中的一个无线电。但是如果我在一个视图中使用这个组件 N 次,那么只有在最后 X 个默认选择中才有效。例如:

例如 让我们 build 聚合器 ui

<g:HTMLPanel>
   <cc:RadioButtonComponent ui:field="one"/>
   <br/>
   <cc:RadioButtonComponent ui:field="two"/>

</g:HTMLPanel>

class

public class AggregatorComponent extends Composite {

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

    interface AggregatorComponentUiBinder extends UiBinder<Widget, AggregatorComponent> {
    }

    @UiField
    RadioButtonComponent one;
    @UiField
    RadioButtonComponent two;
    
    public AggregatorComponent() {
    initWidget(uiBinder.createAndBindUi(this));
    }
}

和示例 RadioButtonComponent ui

<g:HTMLPanel>

   <g:RadioButton ui:field="radioOne" name="radioGroup"/>
   <g:RadioButton ui:field="radioTwo" name="radioGroup"/>
   <br/>
   <g:CheckBox ui:field="checkBox1"/>
</g:HTMLPanel>

和class

public class RadioButtonComponent extends Composite {

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

    interface RadioButtonComponentUiBinder extends UiBinder<Widget, RadioButtonComponent> {
    }

    @UiField
    RadioButton radioOne;

    @UiField
    RadioButton radioTwo;
    
    @UiField
    CheckBox checkBox1;
    
    public RadioButtonComponent() {
    initWidget(uiBinder.createAndBindUi(this));
    radioOne.setValue(true);
    checkBox1.setValue(true);
    }

}

复选框在这种情况下效果很好。

结果如下所示:

并且unselected radio确实检查过
<input type="radio" name="radioGroup" value="on" id="gwt-uid-6" tabindex="0" checked=""> 但是下面这个有相同的检查值,只是 id 不同。

问题

这是一个错误吗?
如何克服这个障碍?

在 GWT 2.8 上测试Java8 Chrome 版本 56.0.2924.87,FireFox 56 和 IE 11

此致

单选按钮根据其名称进行分组,因此您需要为每个组指定不同的名称(将一个名称传递给 RadioButtonComponent 或在其中生成一个唯一的名称)