Exception when dragging and dropping editable table rows. Help needed

This goes out to all the Vaadin experts out there. I have a table that needs support for drag and drop to rearrange their order and each row is editable. The code is as follows:


final Table table = new Table();
table.setDragMode(Table.TableDragMode.ROW);
table.setDropHandler(new DropHandler() {
	@Override
	public void drop(DragAndDropEvent event) {
		DataBoundTransferable transferable = (DataBoundTransferable) event.getTransferable();
		Object sourceRow = transferable.getItemId();

		AbstractSelect.AbstractSelectTargetDetails dropData =
				((AbstractSelect.AbstractSelectTargetDetails) event.getTargetDetails());
		Object targetRow = dropData.getItemIdOver();

		// Don't move if source and target are the same, or there is no target
		if ((sourceRow == targetRow) || (targetRow == null)) {
			return;
		}

		// Remove the source of the drag so we can add it back where requested
		table.removeItem(sourceRow);

		// Check if the drop location is somewhere below the row ...
		if (dropData.getDropLocation() == VerticalDropLocation.BOTTOM) {
			table.addItemAfter(targetRow, sourceRow);
		}
		// ... or somewhere in the middle or above
		else {
			Object rowAbove = table.prevItemId(targetRow);
			table.addItemAfter(rowAbove, sourceRow);
		}
	}

	@Override
	public AcceptCriterion getAcceptCriterion() {
		return new SourceIs(table);
	}
});
table.setSortDisabled(true);
table.setImmediate(true);
table.setWriteThrough(true);
table.setPageLength(16);
table.setEditable(true);

table.setContainerDataSource(container); // BeanItemContainer
table.setTableFieldFactory(new CustomTableFieldFactory());
table.setVisibleColumns(...);
table.setColumnHeaders(...);	

This works fine in most cases except when I enter some text into any editable field and then drag the edited row and drop it anywhere. Whenever this happens, I get the following exception:


Caused by: java.lang.NullPointerException
	at com.vaadin.data.util.AbstractBeanContainer.removeAllValueChangeListeners(AbstractBeanContainer.java:419)
	at com.vaadin.data.util.AbstractBeanContainer.removeItem(AbstractBeanContainer.java:293)
	at com.vaadin.ui.AbstractSelect.removeItem(AbstractSelect.java:843)
	at com.vaadin.ui.Table.removeItem(Table.java:2967)
	at com.nomura.fiet.irs.admin.ui.bloomberg.ScreenLayoutWindow$2.drop(ScreenLayoutWindow.java:110)
	at com.vaadin.terminal.gwt.server.DragAndDropService.handleDropRequest(DragAndDropService.java:106)
	at com.vaadin.terminal.gwt.server.DragAndDropService.changeVariables(DragAndDropService.java:73)
	at com.vaadin.terminal.gwt.server.AbstractCommunicationManager.handleVariableBurst(AbstractCommunicationManager.java:1297)
	... 54 more

Is this just due to a mistake in my understanding or is this a bug in Vaadin? It appears that when I remove the row to rearrange the data model, the table is unable to remove its value change listeners from its editable field.

Many thanks
j

Using: Vaadin 6.6.1

It seems that your container’s getItem(…) method returns null for the itemId you’re trying to remove from your table. Perhaps you could investigate why that is?

Can you explain what you mean? There is no evidence that was the cause and further testing shows that was not the root problem as get item always returns an object as expected.

I don’t think that it is getItem that returns null because there is an if clause that basically fetches the same data and doesn’t do the removeAllValueChangeListeners if the itemId is not found in the item list. I have more of a feeling that it is Item.getItemPropertyIds() that returns null, and that’s why the loop over that collection throws an NPE.

Could you try to isolate the problem to a stand alone Vaadin app, where you remove as much of irrelevant features as possible. I have a feeling that it doesn’t have anything to do with the DnD feature, and that a button that does table.removeItem(table.getValue()); would cause the same after that you’ve edited the textfield and selected the row.

If you can isolate the issue to an own Application class, I’d be happy to take a look on it.