Vaadin Grid with Editor only for some columns

I’m working on showing data from a database on a Grid and works fine so far. I wanted to add editing capabilities and it did work but I’m struggling to make it work only for some columns and not others.
Here’s the current code:

SettingJpaController sc = new SettingJpaController(Lookup.getDefault() .lookup(DatabaseManager.class)
.getEntityManagerFactory());
Grid<Setting> settings = new Grid<>();
TextField value = new TextField();
settings.getEditor().setEnabled(true);
settings.setItems(sc.findSettingEntities());
settings.addColumn(Setting::getSettingName)
.setCaption("Name");
settings.addColumn(setting -> setting.getSettingValue())
.setCaption("Value")
.setEditorComponent(value, Setting::setSettingValue)
.setExpandRatio(1);
settings.getEditor()
.addSaveListener((EditorSaveEvent<Setting> event) ->
{
try {
sc.edit(event.getBean());
} catch (Exception ex) {
LOG.log(Level.SEVERE, null, ex);
}
});
settings.addColumn(Setting::getDescription).setCaption("Description");

As shown above the editor shows for all fields. For this case I only want the value field to be editable. I tried adding .setEditable(false) to the other columns but I get this error:
java.lang.NullPointerException: Column has no editor binding or component defined
makes no sense to me to have to assign and editor, etc. just to disable it so I’m sure I’m missing something. Any idea?


See question in Stackoverflow.

Hi,
What do you mean by ‘the editor shows for all fields’? The editor is the same width as Grid’s rows, but are all columns actually editable, or just the one you defined the editor component for? I think that only the columns, to which you have set editors, should be editable. (Also tested the theory quickly, seems to me that this is true.)
You don’t need to set editor components for columns that you don’t wish to be editable
ever
. In the case that you want them to be editable in certain cases but not others, you would need to set editors and enable and disable them by calling setEditable/getEditable.

-Katri

What I meant is that the editor shows up for all fields not only for the one I configured it for. The other columns are never meant to be editable. If I try to make the others not editable then I get the errors from the original post.

I’m working on Vaadin 8.1.7 if that makes any difference.

You could of course create a ComponentColumn in place of the column(s) you want editable?

-Olli