gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-12-02 00:46:19 25 4
gpt4 key购买 nike

我正在使用 GWT (Google Web Toolkit) 1.5.3 和 GXT (ExtJS) 1.2我只想创建一个简单的表单,其中包含一些在 RPC 调用后生成的单选按钮,以获取一些值

代码:

final FormPanel simple = new FormPanel();
simple.setFrame(true);
simple.setWidth(350);
simple.setHeaderVisible(false);

DateField date = new DateField();
date.setFieldLabel("Date");
simple.add(date);

ListFluxServiceAsync service = (ListFluxServiceAsync)
GWT.create(ListFluxService.class);
ServiceDefTarget target = (ServiceDefTarget)service;
String url = GWT.getModuleBaseURL() + "flux.rpc";
target.setServiceEntryPoint(url);

final RadioGroup radioGroup = new RadioGroup("RadioGroup");
radioGroup.setFieldLabel("Flux");
radioGroup.setOrientation(Orientation.VERTICAL);

service.getAllFlux(new AsyncCallback<List<FluxModelData>>(){

public void onFailure(Throwable caught) {
GWT.log("flux.rpx::onFailure", caught);
MessageBox.alert("what?", "onFailure :" + caught.getMessage(), null);
}

public void onSuccess(List<FluxModelData> result) {

Iterator<FluxModelData> it = result.iterator();
while ( it.hasNext() ){
FluxModelData fmd = it.next();
Radio radio = new Radio();
radio.setName("flux");
radio.setValue(true);
//radio.setRawValue("my very long value");
radio.setBoxLabel(fmd.getDescription());
radioGroup.add(radio);
}

simple.add(radioGroup);
simple.layout(); //we need it to show the radio button

}
});



simple.setButtonAlign(HorizontalAlignment.CENTER);

Button button = new Button("Récupérer");
button.addSelectionListener(new SelectionListener<ButtonEvent>(){

@Override
public void componentSelected(ButtonEvent ce) {

MessageBox.alert("what?", radioGroup.getValue().getRawValue() , null);

}});

simple.addButton(button);


RootPanel.get().add(simple);

我的问题是我无法设置/获取单选按钮值。如果我尝试 setRawValue("xxxxxxx"),我会收到一些空错误,而设置 setValue(boolean) 正在工作,但我期望获得 radio 值而不是标签值。

有什么想法吗?

最佳答案

创建广播

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 - GXT - 如何获取单选按钮值?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/356298/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com