簡體   English   中英

GWT中奇怪的單選按鈕行為

[英]Strange radio button behaviour in GWT

我遇到了一個與RadioButtons相關的奇怪案例GWT。 我構建了一個由內部多個無線電組成的組件,將其稱為X。默認情況下,選擇了X內部的一個無線電。 但是,如果我在一個視圖中使用此組件N次,則僅在最后X個默認選擇中有效。 舉個例子:

為了實例化,我們構建聚合器ui

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

</g:HTMLPanel>

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>

和課

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);
    }

}

復選框在這種情況下效果很好。

結果如下:

在此處輸入圖片說明

收音機確實沒有檢查
<input type="radio" name="radioGroup" value="on" id="gwt-uid-6" tabindex="0" checked="">但此波紋管具有相同的校驗值,只是id不同。

這是一個錯誤嗎?
如何克服這個障礙?

在GWT 2.8 Java 8 Chrome版本56.0.2924.87,FireFox 56和IE 11上進行了測試

最好的祝福

單選按鈕根據其名稱進行分組,因此您需要為每個組指定不同的名稱(將其傳遞給RadioButtonComponent或在其中生成唯一的名稱)

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM