GWT CheckboxCell hinders selection in CellTable

感情迁移 提交于 2019-12-13 19:06:38

问题


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?


回答1:


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.



来源:https://stackoverflow.com/questions/14890619/gwt-checkboxcell-hinders-selection-in-celltable

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!