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.setDataProvider(new FetchItemsCallback<String>() {

    public Stream<String> fetchItems(String filter, int offset, int limit) {
        Bean bean = grid.getEditor().getBinder().getBean();
        return valuesDependendOfBean(bean).stream();
}, new SerializableToIntFunction<String>() {

    public int applyAsInt(String value) {
        Bean bean = grid.getEditor().getBinder().getBean();
        return valuesDependendOfBean(bean).size();
grid.getColumn(COLUMN_ID).setEditorBinding(binder.bind(comboBox, fieldName));

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:

  1. make the FetchItemsCallback return an empty stream if the bean is null;
  2. 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.