Javascript GWT中奇怪的单选按钮行为
我遇到了一个与单选按钮有关的奇怪案例。我构建了由多个内部无线电组成的组件,让我们将其称为X。默认情况下,选择X内部的一个无线电。但是如果我在一个视图中使用这个组件N次,那么只有在最后X个视图中默认选择才起作用。例如: 安装 让我们构建聚合器uiJavascript GWT中奇怪的单选按钮行为,javascript,java,gwt,Javascript,Java,Gwt,我遇到了一个与单选按钮有关的奇怪案例。我构建了由多个内部无线电组成的组件,让我们将其称为X。默认情况下,选择X内部的一个无线电。但是如果我在一个视图中使用这个组件N次,那么只有在最后X个视图中默认选择才起作用。例如: 安装 让我们构建聚合器ui <g:HTMLPanel> <cc:RadioButtonComponent ui:field="one"/> <br/> <cc:RadioButtonComponent
<g:HTMLPanel>
<cc:RadioButtonComponent ui:field="one"/>
<br/>
<cc:RadioButtonComponent ui:field="two"/>
</g:HTMLPanel>
阶级
公共类聚合组件扩展了复合类{
私有静态AggregatorComponentUiBinder=GWT.create(AggregatorComponentUiBinder.class);
接口聚合组件UiBinder扩展UiBinder{
}
@尤菲尔德
RadioButton组件一;
@尤菲尔德
RadioButton组件二;
公共聚合组件(){
initWidget(uiBinder.createAndBindUi(this));
}
}
和示例RadioButtonComponentUI
<g:HTMLPanel>
<g:RadioButton ui:field="radioOne" name="radioGroup"/>
<g:RadioButton ui:field="radioTwo" name="radioGroup"/>
<br/>
<g:CheckBox ui:field="checkBox1"/>
</g:HTMLPanel>
和阶级
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);
}
}
公共类RadioButtonComponent扩展了复合{
专用静态RadioButtonComponentUiBinder uiBinder=GWT.create(RadioButtonComponentUiBinder.class);
接口RadioButton组件UiBinder扩展UiBinder{
}
@尤菲尔德
单选按钮单选机;
@尤菲尔德
RadioButtonRadio2;
@尤菲尔德
复选框1;
公共RadioButtonComponent(){
initWidget(uiBinder.createAndBindUi(this));
radioOne.setValue(真);
复选框1.设置值(真);
}
}
复选框在这种情况下工作得很好
结果如下所示:
而未选的收音机确实已经检查过了
但是下面这一个有相同的检查值,只是id不同
问题
这是一个bug吗?如何克服这个障碍 在GWT2.8Java8上测试 Chrome版本56.0.2924.87、FireFox 56和IE 11
“致意”单选按钮根据其名称分组,因此您需要为每个组指定不同的名称(将一个名称传递给
RadioButtonComponent
或在其内部生成一个唯一的名称)单选按钮根据其名称分组,因此您需要为每个组指定不同的名称(将一个传递给RadioButtonComponent
或在其中生成一个唯一的)
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);
}
}