GWT-GXT-如何获取单选按钮值?

GWT-GXT-如何获取单选按钮值?,gwt,extjs,radio-button,gwt-rpc,gxt,Gwt,Extjs,Radio Button,Gwt Rpc,Gxt,我正在使用GWT(GoogleWebToolkit)1.5.3ETGXT(ExtJS)1.2 我只想创建一个简单的表单,在RPC调用后生成一些单选按钮,以获取一些值 代码: final FormPanel simple=new FormPanel(); simple.setFrame(true); 简单。设置宽度(350); simple.setheadervible(false); DateField date=新的DateField(); 日期。setFieldLabel(“日期”); 简单

我正在使用GWT(GoogleWebToolkit)1.5.3ETGXT(ExtJS)1.2 我只想创建一个简单的表单,在RPC调用后生成一些单选按钮,以获取一些值

代码:

final FormPanel simple=new FormPanel();
simple.setFrame(true);
简单。设置宽度(350);
simple.setheadervible(false);
DateField date=新的DateField();
日期。setFieldLabel(“日期”);
简单。添加(日期);
ListFluxServiceAsync服务=(ListFluxServiceAsync)
create(ListFluxService.class);
ServiceDefTarget=(ServiceDefTarget)服务;
字符串url=GWT.getModuleBaseURL()+“flux.rpc”;
target.setServiceEntryPoint(url);
最终射线组射线组=新射线组(“射线组”);
射线组setFieldLabel(“通量”);
放射组设置方向(方向垂直);
getAllFlux(新的AsyncCallback(){
失败时的公共无效(可丢弃){
log(“flux.rpx::onFailure”,捕获);
MessageBox.alert(“what?”,“onFailure:+catch.getMessage(),null);
}
成功时公开作废(列表结果){
迭代器it=result.Iterator();
while(it.hasNext()){
FluxModelData fmd=it.next();
收音机=新收音机();
radio.setName(“通量”);
radio.setValue(真);
//radio.setRawValue(“我的超长值”);
radio.setBoxLabel(fmd.getDescription());
放射组添加(无线电);
}
简单。添加(放射组);
simple.layout();//我们需要它来显示单选按钮
}
});
simple.setButtonAlign(水平对齐.中心);
按钮按钮=新按钮(“Récupérer”);
addSelectionListener(新建SelectionListener(){
@凌驾
已选择公共无效组件(按钮事件ce){
MessageBox.alert(“什么?”,radioGroup.getValue().getRawValue(),null);
}});
简单。添加按钮(按钮);
RootPanel.get().add(简单);
我的问题是我无法设置/获取单选按钮值。 如果我尝试setRawValue(“xxxxxxx”),我会得到一些空错误,而设置setValue(布尔值)是有效的,但我希望得到的是单选值,而不是标签值


有什么想法吗?

使用radioButton.setItemId()和getItemId()解决它。

我使用
radio.setAttributeValue()
方法设置单选按钮的值。

创建单选按钮

Radio radio = new Radio();  
radio.setBoxLabel("Si");  
radio.setValue(true);
radio.setValueAttribute("true");

Radio radio2 = new Radio();  
radio2.setBoxLabel("No");
radio2.setValueAttribute("false");

RadioGroup radioGroup = new RadioGroup();  
radioGroup.setFieldLabel("Afecto");  
radioGroup.add(radio);  
radioGroup.add(radio2);
获取选定值

Boolean b = Boolean.parseBoolean(radioGroup.getValue().getValueAttribute());

您需要扩展GWT RadioButton类ex:

public class ExtRadioButton extends RadioButton {
    public ExtRadioButton(String name, String label) {
        super(name, label);
        // TODO Auto-generated constructor stub
    }

    public void setValue(String value)
    {
        Element span = getElement();
        Element input = DOM.getChild(span,0);
        DOM.setElementAttribute(input,"value",value);
     }

}
默认情况下,它只允许布尔值。初始化单选按钮后,您需要设置值。

请查看此选项

 Radio radio1 = new Radio();
.............
 Radio radio2 = new Radio();
.............

in order to get value you can do as follow

String value = (radio1.getValue()) ? radio1.getText() : radio2.getText(); 

另一种方法是使用
radio.setValueAttribute(String)
方法。然后,您可以在RadioGroup上使用以下代码来获取单击单选按钮的set'value'属性:

radioGroup.addListener(Events.Change, new Listener<BaseEvent>() {
  @Override
  public void handleEvent(BaseEvent be) 
  {
    final RadioGroup radioGroup = (RadioGroup)be.getSource();

    final Radio clickedRadioBtn = radioGroup.getValue();

    final String valueAttribute = clickedRadioBtn.getValueAttribute(); // Correct !!!

  }
});
radioGroup.addListener(Events.Change,new Listener()){
@凌驾
公共无效handleEvent(BaseEvent be)
{
最终的放射组放射组=(放射组)be.getSource();
最终收音机单击RadiobN=radioGroup.getValue();
最终字符串valueAttribute=clickedRadiobN.getValueAttribute();//正确!!!
}
});
radio.setValue()正是我想要找到的!
radioGroup.addListener(Events.Change, new Listener<BaseEvent>() {
  @Override
  public void handleEvent(BaseEvent be) 
  {
    final RadioGroup radioGroup = (RadioGroup)be.getSource();

    final Radio clickedRadioBtn = radioGroup.getValue();

    final String valueAttribute = clickedRadioBtn.getValueAttribute(); // Correct !!!

  }
});
            Radio includeButton = new Radio();
        Radio excludeButton = new Radio();
        RadioGroup radioGroup = new RadioGroup();




            radioGroup.add(includeButton);
    radioGroup.add(excludeButton);

           includeButton.setvalue(true)//false