简体   繁体   English

获取 EXT-GWT RadioGroup 中选定 RadioButton 的名称

[英]Get Name of selected RadioButton in EXT-GWT RadioGroup

I have following code:我有以下代码:

final Radio trDelRadio = new Radio();
trDelRadio.setName("TDRADIO");
trDelRadio.setBoxLabel("Training");

final Radio cdcRadio = new Radio();
cdcRadio.setName("CDCRADIO");
cdcRadio.setBoxLabel("Content");

final Radio msRadio = new Radio();
msRadio.setName("MSRADIO");
msRadio.setBoxLabel("Management");

final Radio osRadio = new Radio();
osRadio.setName("OSRADIO");
osRadio.setBoxLabel("Outsourcing");


final RadioGroup radioGroup = new RadioGroup();
radioGroup.setOrientation(Orientation.VERTICAL);
radioGroup.add(trDelRadio);
radioGroup.add(cdcRadio);
radioGroup.add(msRadio);
radioGroup.add(osRadio);
radioGroup.addListener(Events.Change, new Listener<BaseEvent>(){
       public void handleEvent(BaseEvent be) {
              GWT.log("Service type: " + radioGroup.getValue().getBoxLabel(), null);
        }
});

In this code I'm using GXT 2.0.1 create four radio buttons and then combining them into the radio button group.在此代码中,我使用 GXT 2.0.1 创建四个单选按钮,然后将它们组合到单选按钮组中。

Line线

GWT.log("Service type: " + radioGroup.getValue().getBoxLabel(), null);

is retrieving Label of selected check box and works fine, but when I'm trying to get name or any other information it's getting value of the RadioGroup.正在检索选定复选框的标签并且工作正常,但是当我尝试获取名称或任何其他信息时,它正在获取 RadioGroup 的值。 What am I doing wrong here?我在这里做错了什么? How do I get selected radio button in RadioGroup?如何在 RadioGroup 中获得选定的单选按钮?

我使用radio.setValueAttribute(String value)方法来存储值。

I think, that's you need.我想,这就是你需要的。

radioGroup.addListener(Events.Change, new Listener<FieldEvent>() {
    @Override
    public void handleEvent(FieldEvent fe) {
        GWT.log(fe.getField().getName() + " : " + fe.getValue());
    }
});

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM