0

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!

enrybo
  • 1,787
  • 1
  • 12
  • 20
Ser Yoga
  • 466
  • 1
  • 6
  • 18
  • Can you put some code in the question? Perhaps the `ValueUpdater` implementation as well as the `KeyProvider` for the `DataListProvider` and `MultiSelectionModel`. – enrybo May 07 '13 at 16:36
  • put a breakpoint in your `KeyProvider` and make sure it is really called. Could it be that the an exception is thrown when you save the instance ? If the exception is not caught it might break the execution of the de-selection code (check Chrome Developer Tools console) – Ümit May 08 '13 at 11:19
  • i tried with breakpoints the idContact value in datalistprovider and celltable had the same value and the rpc calls onSuccess because i get in the breakPoint in onChange(); (i tried there to call clear() when i updated the contact but the old item was still selected???) – Ser Yoga May 08 '13 at 11:29

1 Answers1

0

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.

enrybo
  • 1,787
  • 1
  • 12
  • 20