Reputation: 65
Is it possible to use a custom Converter for the ListSelect Component? This is what I tried:
ListSelect ls = new ListSelect();
ls.setConverter((Converter) new MyCustomConverter());
ObjectToDisplay ots = new ObjectToDisplay();
// ls.setConvertedValue(ots ); // Converter is called but ListSelect stays empty
lsConstruction.addItem(ots ); // Did not work
However, the ListSelect stays empty after adding a value.
Thanks for any help!
Upvotes: 0
Views: 469
Reputation: 1127
Use setItemCaption()
:
final ListSelect ls = new ListSelect ();
final BeanItemContainer<ObjectToDisplay> container = new BeanItemContainer<>(ObjectToDisplay.class, objectList);
ls.setContainerDataSource(container);
for (final ObjectToDisplay o : objectList){
ls.setItemCaption(o, yourDesiredFormatFunction(o));
}
Adding object programmatically would be done with container.addItem(object)
.
Regarding the use of Converters: this post elaborates on Converters used with AbstractSelect implementations such as ListSelect and ComboBoxes.
Upvotes: 1