-
24 Apr 2008 5:05 AM #1
[FIXED] ComboBox Store cannot be changed
[FIXED] ComboBox Store cannot be changed
The example code below illustrates some problems with the ComboBox:
- When the combox is created its Store must have at least one item, otherwise the Combo wont display anything, even if the store is changed in a listener etc.
- .
- Calling removeAll on a ComboBox's Store doesn't remove the item that was part of the Store when combobox was created.
- .
- In the example attached, if you click the ComboBox before you click the button, the ComboBox will not display properly after you add items by clicking the button.
- .
- If you click the button first, the combo will layout ok, but the "dummy" item is still there.
Code:public class Main implements EntryPoint { private Viewport viewport; public class MyModel extends BaseModel { public MyModel() { } public MyModel(String name, Integer age) { set("name", name); set("age", age); } } public void onModuleLoad() { viewport = new Viewport(); viewport.setLayout(new FlowLayout()); Store store = new Store(); // if next line is commented out the combo doesn't display any items store.add(new Record(new MyModel("dummy", 5))); final ComboBox combo = new ComboBox(); combo.setWidth(100); combo.fieldLabel = "whatever"; combo.displayField = "name"; // if next line is commented out the combo doesn't display any items combo.setStore(store); Button btn = new Button("Fill combo", new SelectionListener() { public void componentSelected(ComponentEvent ce) { Store s = combo.getStore(); // following command doesn't work, "dummy" item still visible in list s.removeAll(); s.add(new Record(new MyModel("John1", 30))); s.add(new Record(new MyModel("John2", 31))); s.add(new Record(new MyModel("John3", 32))); s.add(new Record(new MyModel("John4", 33))); combo.recalculate(); // no effect } }); viewport.add(combo); viewport.add(btn); viewport.layout(true); RootPanel.get().add(viewport); } }
-
24 Apr 2008 1:03 PM #2
There are some issues I am working on to support mods to the store after the combo is rendered. I will post back when they are done, which will be before beta2.
-
27 Apr 2008 10:28 AM #3
The height of the drop down list was not being reset after first being displayed. This was causing the problem when not having a single record and the problems when adding records dynamically.
removeAll was not clearing any existing items.
All the fixes are in SVN.
-
30 Apr 2008 12:12 AM #4
Hello Darrel,
I just tried the beta2. The problem still remains:
- removeAll doesn't remove any items
- rendering a ComboBox without first setting the store throws an exception
Code:public class ComboBoxProblem implements EntryPoint { class MyModel extends BaseModel { MyModel() { } MyModel(String name, Integer age) { set("name", name); set("age", age); } } public void onModuleLoad() { Viewport viewport = new Viewport(); viewport.setLayout(new FlowLayout()); Store store = new Store(); // if next line is commented out the ComboBox throws exception store.add(new MyModel("dummy", 5)); final ComboBox combo = new ComboBox(); combo.setWidth(100); combo.setFieldLabel("Whatever"); combo.setDisplayField("name"); // if next line is commented out the ComboBox throws exception combo.setStore(store); Button btn = new Button("Fill combo", new SelectionListener() { public void componentSelected(ComponentEvent ce) { Store s = combo.getStore(); // following command doesn't work, "dummy" item remains in list // and it's not selectable s.removeAll(); s.add(new MyModel("John1", 30)); s.add(new MyModel("John2", 31)); s.add(new MyModel("John3", 32)); s.add(new MyModel("John4", 33)); } }); viewport.add(combo); viewport.add(btn); viewport.layout(true); RootPanel.get().add(viewport); } }


Reply With Quote