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

StackOverflow https://stackoverflow.com/questions/15894341

  •  02-04-2022
  •  | 
  •  

Вопрос

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?

Это было полезно?

Решение

You forgot to add DefaultSelectionEventManager i guess.

Change this line

cellTable.setSelectionModel(selectionModel);

to

cellTable.setSelectionModel(selectionModel,
                     DefaultSelectionEventManager.<T> createCheckboxManager());
Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top