Strange null entity error with dataGrid.editItem(<item>)

I have an application with a dataGrid in v7 (translating from v6.10). I create a new entity and add it to the grid, then try to execute a editItem() call to navigate to the row I just created and open the editor. I get this:

llegalArgumentException: Entity must be non null

The code looks like this:

Updtrans updtrans = metadata.create(Updtrans.class);
updtransNestedDs.addItem(updtrans);
pinTable.editItem(updtrans);

updtransNestedDs is the datasource for the datagrid. The error occurs on the editItem() call.

<dataGrid id="pinTable" editorEnabled="true" height="350px" width="300px"
          datasource="updtransNestedDs">
    <actions>
        <action id="create" invoke="onAddPin" shortcut="CTRL-ARROW_DOWN"/>
        <action id="Save" invoke="onSavePin"/>
        <action id="remove" invoke="onRemove"/>
    </actions>
    <columns>
        <column id="mailfile" property="mailfile"/>
    </columns>
</dataGrid>

When I step through the code at a low level, I get to this point in CollectionPropertyDatasourceImpl.java:

@Override
public T getItem(K id) {
    backgroundWorker.checkUIAccess();

    Collection<T> collection = getCollection();
    if (collection != null) {
        for (T t : collection) {
            if (t.getId().equals(id)) {
                return t;
            }
        }
    }
    return null;
}

This code returns null. But I can see that the ID is in the collection! Here is a screenshot:

image

As you can see (I hope), the ID fields ARE the same (4504).

Can anybody tell me what is going on here?

I think I found the issue. The problem is that the editItem() call requires an ID, not an Entity. And, to make matters worse, editItem() is deprecated. So, the correct code is:

pinTable.edit(updtrans);

Strangely, the documentation still shows:

editItem() - opens the editor interface for the provided item. Scrolls the grid to bring the item to view if it is not already visible.

I mistakenly interpreted that to mean an Entity. It actually requires an ID. Maybe the documentation meant to say “edit” rather than “editItem”?

Hi,

Thank you for reporting the problem, I’ve create a GitHub issue.