jcera
jcera

Reputation: 345

GWT: SelectionChangeEvent.Handler does not detect deselect of row on CellTable

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?

Upvotes: 2

Views: 2560

Answers (1)

Suresh Atta
Suresh Atta

Reputation: 122026

You forgot to add DefaultSelectionEventManager i guess.

Change this line

cellTable.setSelectionModel(selectionModel);

to

cellTable.setSelectionModel(selectionModel,
                     DefaultSelectionEventManager.<T> createCheckboxManager());

Upvotes: 3

Related Questions