Search code examples
databasegwtasynchronouscollectionsgxt

How to repopulate a GXT ComboBox on each click?


I'm using a simple ComboBox in GXT that gets its values from the database.

What I want is that everytime that the user clicks (expands) the ComboBox, it will check and re-populate it with the latest entries in the database (in case they've changed).

Right now I'm doing something like:

ProtocolProperties protocolProperties = GWT.create(ProtocolProperties.class);
final ListStore<ProtocolDto> protocolStore = new ListStore<ProtocolDto>(protocolProperties.id());

protocol = new ComboBox<ProtocolDto>(protocolStore, protocolProperties.name());

    protocol.addExpandHandler(new ExpandHandler() {
                @Override
                public void onExpand(ExpandEvent event) {
                    protocolStore.clear();

                    ProtocolDto emptyDto = new ProtocolDto();
                    emptyDto.setId(-1);
                    emptyDto.setName("None");
                    protocolStore.add(emptyDto);

                    AppEntryPoint.getLogbookdataservice().getAllProtocols(new AsyncCallback<List<ProtocolDto>>() {

                        @Override
                        public void onSuccess(List<ProtocolDto> result) {               
                            protocolStore.addAll(result);
                        }

                        @Override
                        public void onFailure(Throwable caught) {
                            // TODO Auto-generated method stub

                        }
                    });
                }
            });

Thanks to anyone who takes the time to answer this.


Solution

  • You should be looking at Async Support in Combobox instead of reinventing a square wheel.

    Sencha Demo - http://www.sencha.com/examples/#ExamplePlace:advancedcombobox

    Stackoverflow - Also one approach discussed here - Dynamic Autosuggest Combobox in GXT

    GXT Forum - http://www.sencha.com/forum/showthread.php?185967-ComboBox-doQuery-method-seems-not-working-with-Remote-Loader