-
25 Nov 2008 4:49 PM #1
[FIXED] [1.1] ComboBox setModelStringProvider doesn't work
[FIXED] [1.1] ComboBox setModelStringProvider doesn't work
I've noticed that setting a ModelStringProvider on ComboBox doesn't work. If I set a displayField on the ComboBox, my ModelStringProvider doesn't get called at all. If I don't set a displayField on the ComboBox, my ModelStringProvider gets called with the property "text"; Returning anything from the ModelStringProvider in this case produces an empty dropdown.
Code:
In the code above, the dropdown has two items but nothing is displayed (should be "ANYTHING" displayed twice). If you comment in "myBox.setDisplayField('name')" then the ComboBox has text, but it's "User 1" and "User 2", not "ANYTHING" twice.Code:Map data1 = new HashMap(); Map data2 = new HashMap(); data1.put("name", "User 1"); data2.put("name", "User 2"); FormPanel panel = new FormPanel(); ListStore store = new ListStore(); store.add(new BaseModelData(data1)); store.add(new BaseModelData(data2)); ComboBox myBox = new ComboBox(); myBox.setStore(store); myBox.setModelStringProvider(new ModelStringProvider() { public String getStringValue(ModelData modelData, String s) { return "ANYTHING"; } }); // it doesn't matter if this is commented in or not //myBox.setDisplayField("name"); panel.add(myBox); panel.layout(); RootPanel.get().add(panel);
-
26 Nov 2008 8:29 PM #2
ModelStringProvider support is not implemented with the current ComboBox code. I have now deprecated its use. The same type of functionality is provided via of the new ModelProcessor class. See the following code:
The new code is in SVN. With the current code, you can use a custom XTemplate to format the data used in the combos list. See the ComboBoxExample class for an example.Code:public void onModuleLoad() { ListStore<State> states = new ListStore<State>(); states.add(TestData.getStates()); ComboBox<State> combo = new ComboBox<State>(); combo.setStore(states); combo.setSimpleTemplate("{test}"); combo.setWidth(200); // format the list values combo.getView().setModelProcessor(new ModelProcessor<State>() { public State prepareData(State model) { model.set("test", model.getAbbr() + " " + model.getName()); return model; } }); // format combo display value combo.setPropertyEditor(new ListModelPropertyEditor<State>(){ @Override public String getStringValue(State value) { return value.getAbbr() + " " + value.getName(); } }); RootPanel.get().add(combo); }
-
27 Nov 2008 6:04 AM #3
Nice improvement, Darell. By the way, I'm not sure to see the differences between "format the list values" and "format combo display value". "format combo display value" = text of the associated LabelField ?
-
27 Nov 2008 7:44 AM #4
Yes.format combo display value = text of the associated LabelField


Reply With Quote