PDA

View Full Version : ComboBoxFieldBinding



shinkell
4 Apr 2011, 12:38 PM
Based on code from this thread:
http://www.sencha.com/forum/showthread.php?112660-How-to-combobox-databinding.&highlight=comboboxfieldbinding

Could we add the following code to handle a combobox fieldbinding?



import com.extjs.gxt.ui.client.binding.Converter;
import com.extjs.gxt.ui.client.binding.FieldBinding;
import com.extjs.gxt.ui.client.data.ModelData;
import com.extjs.gxt.ui.client.widget.form.ComboBox;
import com.extjs.gxt.ui.client.widget.form.Field;


public class ComboBoxFieldBinding extends FieldBinding {

public ComboBoxFieldBinding(Field field, String property) {
super(field, property);
if (field instanceof ComboBox) {
final ComboBox<ModelData> combo = (ComboBox<ModelData>) field;
setConverter(new Converter() {

@Override
public Object convertFieldValue(Object value) {
if (value instanceof ModelData) {
ModelData val = (ModelData) value;
return val.get(combo.getValueField());
} else {
return value;
}
}

@Override
public Object convertModelValue(Object value) {
return combo.getStore().findModel(combo.getValueField(), value);
}

});
}
}

}