1

I discovered that if you have a GWT CellTable and add a column that contains a CheckboxCell, the selection via a SingleSelectionModel does not work anymore. This cell type does hinder the row selection. Following a code sample that demonstrates this behaviour in 2.5.0.rc1.

final CellTable<LicenseDto> licenseTable = new CellTable<LicenseDto>();
final SingleSelectionModel<LicenseDto> selectionModel = new SingleSelectionModel<LicenseDto>();
licenseTable.setSelectionModel(selectionModel);


//--- If I add this column, the selection does work.
Column<LicenseDto, String> workingColumn = new Column<LicenseDto, String>(new TextCell()) {

    @Override
    public String getValue(LicenseDto object) {
        return "Works";
    }
};
workingColumn.setFieldUpdater(new FieldUpdater<LicenseDto, String>() {

    @Override
    public void update(int index, LicenseDto object, String value) {
        ;
    }
});
licenseTable.addColumn(workingColumn);


//--- If I add this column, the selection does NOT work anymore.
Column<LicenseDto, Boolean> notWorkingColumn = new Column<LicenseDto, Boolean>(new CheckboxCell(true, true)) {

    @Override
    public Boolean getValue(LicenseDto object) {
        return object.getEnabled();
    }
};
notWorkingColumn.setFieldUpdater(new FieldUpdater<LicenseDto, Boolean>() {

    @Override
    public void update(int index, LicenseDto object, Boolean value) {
        presenter.enableLicense(object, value);
    }
});
licenseTable.addColumn(notWorkingColumn);

initWidget(licenseTable);

You can combine multiple cells and add them to the table (e.g. LinkActionCell etc). As long as there is no CheckboxCell, the blue selection with the SingleSelectionModel works like a charm. Does anyone see what I do wrong with this CheckboxCell or is there a bug?

enrybo
  • 1,787
  • 1
  • 12
  • 20
Adrian
  • 281
  • 5
  • 14
  • What are you trying to do? should clicking a row select it? also check the checkbox? should checking the checkbox select the row? And what exactly happens when you add that `CheckboxCell`? – Thomas Broyer Feb 15 '13 at 10:08
  • I am trying to keep the row selected (highlighted in blue) as long as no other row is selected (please see my [previous post](http://stackoverflow.com/questions/14851651/gwt-celltable-keep-focus-on-selected-row)). It does not matter on which cell the user clicks. The selection model actually does what I want to do. The problem now is, that if I add a CheckboxCell, it seams that the selectionModel does not work anymore (if you add a SelectionChangeHandler to the model, it does not get fired anymore). – Adrian Feb 15 '13 at 10:36
  • 2
    If the checkbox doesn't control or depends on the selection, why are you using `new CheckBox(true, true)` then? (might not fix your issue, just a remark in passing) – Thomas Broyer Feb 15 '13 at 11:05

1 Answers1

3

Thank you Thomas! The problem was that I set handlesSelection = true even thought I don't handle anything. Setting it to false solves the problem. By the way, I add a fieldUpdater to the column to handle a tick or untick of the checkbox:

Column<LicenceDto, Boolean> enableLicenseColumn = new Column<LicenceDto, Boolean>(new CheckboxCell(false, false)) {

    @Override
    public Boolean getValue(LicenceDto object) {
        return object.getEnabled();
    }
};
enableLicenseColumn.setFieldUpdater(new FieldUpdater<LicenceDto, Boolean>() {

    @Override
    public void update(int index, LicenceDto object, Boolean value) {
        presenter.enableLicense(object, value);
    }
});

The question is answered.

Patricia
  • 7,752
  • 4
  • 37
  • 70
Adrian
  • 281
  • 5
  • 14