2

So I have this piece of code which is almost exactly the same on the GWT Showcase

selectionModel = new SingleSelectionModel<T>(keyProvider);
cellTable.setSelectionModel(selectionModel);

selectionModel.addSelectionChangeHandler(new SelectionChangeEvent.Handler() {
    public void onSelectionChange(SelectionChangeEvent event) {
        selectedRow = ((SingleSelectionModel<T>).selectionModel)
                .getSelectedObject();

    });

Column<T, Boolean> checkColumn = new Column<T, Boolean>(new CheckboxCell(true, false)) {
            @Override
            public Boolean getValue(T object) {
                return cellTable.getSelectionModel().isSelected(object);
            }
        };
        cellTable.addColumn(checkColumn, SafeHtmlUtils.fromSafeConstant("<br/>"));

The problem is, when I uncheck the checkbox the SelectionChangeEvent doesn't handle it. The only instance the onSelectionChange is being called, is when I select another record, but deselecting a record doesn't invoke this method.

any help?

jcera
  • 345
  • 2
  • 11

1 Answers1

3

You forgot to add DefaultSelectionEventManager i guess.

Change this line

cellTable.setSelectionModel(selectionModel);

to

cellTable.setSelectionModel(selectionModel,
                     DefaultSelectionEventManager.<T> createCheckboxManager());
Suresh Atta
  • 120,458
  • 37
  • 198
  • 307
  • wow. thanks! this solved the problem, anyway, I'm quite new to GWT, can you please explain why do I need to change it? – jcera Apr 09 '13 at 06:57
  • when you pass that DefaultSelectionEventManager.createCheckboxmanager() it Constructs a new DefaultSelectionEventManager that triggers selection when any checkbox in any column is clicked. – Suresh Atta Apr 09 '13 at 07:03
  • Previously when you clicked on row,its taking click event of entire row.when you click the checkbox again there is no difference,again the click event fires but wont tell that deselect the selection. – Suresh Atta Apr 09 '13 at 07:06