PDA

View Full Version : radio group binding



hiinsu
28 Jun 2010, 7:41 AM
Hi,
I'd like to know how to bind a radio group.



public class FormBindingTest extends FormPanel{
@Override
protected void onRender(Element parent, int index) {
super.onRender(parent, index);

// initialize
setFrame(true);
setLayout(new FormLayout());

// fields
TextField<String> name = new TextField<String>();
name.setName("name");
name.setFieldLabel("Name");
add(name);

TextField<String> number = new TextField<String>();
number.setName("number");
number.setFieldLabel("Number");
add(number);

RadioGroup gender = new RadioGroup();
Radio male = new Radio();
male.setName("male");
male.setBoxLabel("Male");
Radio female = new Radio();
female.setName("female");
female.setBoxLabel("Female");
gender.setName("gender");
gender.setFieldLabel("Gender");
gender.add(male);
gender.add(female);
add(gender);

// json model type
ModelType type = new ModelType();
type.setRoot("result");
type.addField("name", "name");
type.addField("number", "number");
type.addField("gender", "gender");

// json loader
ScriptTagProxy<ListLoadResult<ModelData>> proxy =
new ScriptTagProxy<ListLoadResult<ModelData>>(url);
JsonLoadResultReader<ListLoadResult<ModelData>> reader =
new JsonLoadResultReader<ListLoadResult<ModelData>>(type);
BaseListLoader<ListLoadResult<ModelData>> loader =
new BaseListLoader<ListLoadResult<ModelData>>(proxy, reader);
final ListStore<ModelData> store = new ListStore<ModelData>(loader);

// binding
final FormBinding binding = new FormBinding((FormPanel) this);
// TODO: radiogroup binding
binding.autoBind(); // this does not bind non text/label field
binding.setStore(store);

// load data
loader.load();

// TODO : listen to store data change event
Timer t = new Timer(){
@Override
public void run() {
binding.bind(store.getAt(0));
}
};
t.schedule(1000);
}