vaadin-miki/super-fields

Add an existing object to the collection of a CollectionField

Closed this issue · 2 comments

CollectionField allows adding a new row using .add() or .add(index), but this element is null by default. How to best add a new or existing object?

@waterhd first of all, thank you for using my components!

in general, collection field does not add elements to the collection - it only adds a new component using CollectionValueComponentProvider; so one way to add an existing object is to just have an implementation of that interface that does it (i.e. it creates a component and sets its value to whatever object you want)

the other option is to get the value of the collection field, then create a new collection with elements from that and the new element, then set the value of the collection field to that :) a bit convoluted, though (simply getValue().add(object) will not work, as the value of the field has not changed - it is still the same collection)