Important Notice - Forums is archived
To simplify things and help our users to be more productive, we have archived the current forum and focus our efforts on helping developers on Stack Overflow. You can post new questions on Stack Overflow or join our Discord channel.

TUTORIALVaadin lets you build secure, UX-first PWAs entirely in Java.
Vaadin lets you build secure, UX-first PWAs entirely in Java.
Free ebook & tutorial.
Calling javascript synchronously by Enver Haase, 2 weeks ago
How to make Editor of Grid dependent of editing row (bean)
Hi Vaadins!
I'm trying to build an inline editor. I wan't a combobox for a field, which values are dependent on the editing row.
With the following solution, I get a NPE for the bean of the editor.
ComboBox<String> comboBox = new ComboBox<>();
comboBox.setEmptySelectionAllowed(false);
comboBox.setDataProvider(new FetchItemsCallback<String>() {
@Override
public Stream<String> fetchItems(String filter, int offset, int limit) {
Bean bean = grid.getEditor().getBinder().getBean();
return valuesDependendOfBean(bean).stream();
}
}, new SerializableToIntFunction<String>() {
@Override
public int applyAsInt(String value) {
Bean bean = grid.getEditor().getBinder().getBean();
return valuesDependendOfBean(bean).size();
}
});
grid.getColumn(COLUMN_ID).setEditorBinding(binder.bind(comboBox, fieldName));
Last updated on
The ComboBox invokes the data provider right away, before any row is actually edited in the Grid. Hence the editor's bean is null. I'd try the following approach:
- make the FetchItemsCallback return an empty stream if the bean is null;
- Add a value change listener to the combobox itself; when the value is changed, just call getDataProvider().refreshAll() to repopulate the ComboBox's data. If that's not possible, you can override EditorImpl's onEdit method and refresh the combobox there.
Last updated on
You cannot reply to this thread.