I came across an strange case GWT related with RadioButtons. I built component which consist from multiple radio inside lets call it X. One radio inside X is selected by default. But if I use this component N times in one view then only in the last X default selection works. As an example:
For instace let's build aggregator 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));
}
}
and example 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>
and 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);
}
}
checkbox works well in this case.
Result looks like this:
and unseleced radio has indeed checked
<input type="radio" name="radioGroup" value="on" id="gwt-uid-6" tabindex="0" checked="">
but this one bellow has the same checked value only id is different.
QUESTION
Is this a bug ?
How to overcome this obstacle ?
Tested on GWT 2.8 Java 8 Chrome Version 56.0.2924.87, FireFox 56 and IE 11
Best regards
单选按钮根据其名称进行分组,因此您需要为每个组指定不同的名称(将其传递给RadioButtonComponent
或在其中生成唯一的名称)
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.