Search in one GWT ComboBox affects on other ComboBox with the same store

117 Views Asked by At

I'm using com.extjs.gxt.ui.client.widget.form.ComboBox GWT version 2.8.2 and gxt 2.3.1a . I have 2 comboboxes that have the same storage with many values. When I do search in one combobox I see in debug ComboBox lastquery value same as in search string and only single found value in the CombobBox store. But same value I see in other CombobBox which use same storage. So when I'm trying to work with other comboboxes connected (by listener) to second combobox I get an error because I can't load the required values.

com.google.gwt.core.client.JavaScriptException: (TypeError) : Cannot read properties of null (reading 'getValue__Ljava_lang_Object_2') at Unknown.TypeError: Cannot read properties of null(Unknown@-1)

Maybe some option exists to allow to use of the same storage in several ComboBoxes without affecting each other, i.e. not limit storage with filtered by search string values? Using 2 storages by creating 2 copies is not preferable. Thanks in advance.

UPD: combobox2.getValue() gives null when search was performed earlier. How I can reload storage in this case?

UPD: I created 2 comboboxes with the same storage:

private final ListStore<ComboBoxItemModel<String>> countryStore;

public ComboBox<ComboBoxItemModel<String>> createCountryCombobox() {
    ComboBox<ComboBoxItemModel<String>> countriesComboBox = new ComboBox<>();
    countriesComboBox.setFieldLabel("Country");
    countriesComboBox.setStore(countryStore);
    countriesComboBox.setAllowBlank(false);
    countriesComboBox.setTriggerAction(ComboBox.TriggerAction.ALL);
    countriesComboBox.setDisplayField(ComboBoxItemModel.COMBO_BOX_ITEM_NAME);
    countriesComboBox.setValue(countriesComboBox.getStore().getAt(0));
    countriesComboBox.setForceSelection(true);
    countriesComboBox.setEditable(true);

    return countriesComboBox;
}

setEditable(true) option allows to search countries in the list, but it delete values in the storage as result. So I can't load values for other fields connected to second combobox without manual selection in combobox2.

1

There are 1 best solutions below

0
Valeriy K. On

Seems using two storage is quite a simple solution. Other solutions that I tried look like a workaround. I just create copies and it works fine:

ListStore<ComboBoxItemModel<String>> store = new ListStore<>();
store.add(countryStore.getModels());
countriesComboBox.setStore(store);