I'm populating a ListBox with a list of entities from a MySQL source. I can't see how to tell it which field to use as its ID, and which to use as its display.
For ComboBox I can use setItemLabelGenerator to tell it which field to use for display, but I can't see what the equivalent would be for ListBox.
ListBox<MyEntitySource> entityListBox = new ListBox<MyEntitySource>();
List<MyEntitySource> entitySource = (List<MyEntitySource>) entityRepository.findAll();
entityListBox.setItems(entitySource);
This ends up displaying as eg: MyEntity{id=1, description=Item 1}
How do I tell it to hold the ID as field "id" and display the value as field "description"?
You need to apply a renderer for the items, something like:
entityListBox.setRenderer(new TextRenderer<>(entity -> entity.getDescription()));