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?