It’s always struck me as odd that an Item cannot be passed to a container to add it.
Right now a typical flow when adding items to a container is:
- call addItem
- blank item is added to the container
- ItemSetChangeEvent is fired for the blank item
- edit item
- ValueChangeEvents are fired for the item properties
This is a little awkward as steps 2,3 cause components bound to the container to show an empty row because no data has been provided until step 4. This works ok when doing spreadsheet style editing of a table, but doesn’t work well when adding items through a seperate form.
To get round this, I tend to implement a method with signature:
void addItem(Item item)
This way an already populated new item can be added to the container in one operation.
Is there any reason why addItem(Item item) is not already part of the Container interface? Is there a better approach?