ListSelect - item is bean instead of String


I have a user object which in turn has a list of cost centres. Each cost center has an id and a name. I want to display a multi select which displays the cost centers when editing the user.

The problem I am having is firstly displaying the name of the cost center instead of the reference to the instance (com.example.CostCenter@34dfe3). I can override the toString method for the class but that is a hack not to mention I have logic for the view inside the domain class. And this logic could change in other parts of the app.

So I guess what I am after is an example where the items in the list are beans and not just simple Strings.

Any ideas?

This is typically solved with the BeanItemContainer and setItemCaptionPropertyId:

Thanks that manages to solve the problem of display the name attribute of the cost center. :smiley:

But I still cannot get it to show the selected cost centers when displaying the form. And it throws an error when trying to save the cost centers … obviously because I do not have something mapped correctly with the list select for cost centers and the user object which contains a List attribute.$ConversionException: java.lang.NoSuchMethodException: java.util.List.(java.lang.String)
	at com.vaadin.ui.AbstractField.commit(
	at com.vaadin.ui.Form.commit(
	at com.henkel.ccpwvaadin.view.UserFormView.buttonClick(