Question

Hello I have a Contact class with informations which i show in a CellTable. The CellTable has a DataListProvider, MultiSelectionModel and KeyProvider which checks the id of the Contact.

DataListProvider and CellTable have the same KeyProvider.

if i only select/deselect the items in the CellTable and show them in a TextBox ists working fine. But the when i change the value of the Contact item in the TextBox(Contact instance) and try to deselect the item the selectionmodel says its still selected?

I tried with clear() but its still selected!

GWT 2.5 / FireFox

ProvidesKey<Contact> keyProvider = new ProvidesKey<Contact>(){
    @Override
    public Object getKey(Contact item) {
        return item.getIdContact();
    }
};


public MyCellTable(boolean canLoad, Integer pagesize, ProvidesKey<T> keyProvider) {
    super(-1, resource, keyProvider);

    selectionModel = new MultiSelectionModel<T>();
    selectionModel .addSelectionChangeHandler(new SelectionChangeEvent.Handler() {

        @Override
        public void onSelectionChange(SelectionChangeEvent event) {
            selectionChange();
        }
    });

    dataProvider = new ListDataProvider<T>(keyProvider);
    dataProvider.addDataDisplay(this);
}

in the selection event i call

protected void selectionChange(){
    Contact c = grid.getGrid().getSelectedItem();
    if(c != null){
        cpForm.enable();
        cpForm.clear();
        form.bind(c); // Formular which updates the selected instance 
        cpForm.add(form);
    }else{
        cpForm.disable(noseletionText);
    }
}

i have no ValueUpdater

when i select an item i generate a formular and if i change something i call:

@Override
public void save() {
    super.save();
    ContactServiceStore.get().updateContact(manager.getBean(),
            new MyAsyncCallback<Void>() {

                @Override
                public void onSuccess(Void result) {
                    onchange();
                }

            });
}

i if call the method without changes on the contact its still working and i can deselect but when i change the name or something else i cant select other items or deselect the current item!

Was it helpful?

Solution

You're not actually using your ProvidesKeys in your MultiSelectionModel. You need to create your MultiSelectionModel like so:

MultiSelectionModel<T> selectionModel = new MultiSelectionModel<T>(keyProvider);

If you don't supply the MultiSelectionModel with a ProvidesKey it will use the actual object as a key.

Make sure you also add the MultiSelectionModel to the table:

cellTable.setSelectionModel(selectionModel);

The reason selectionModel.clear() wasn't working was because selectionModel was not set to the table.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top