ListSelect - item is bean instead of String

Hi,

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?
Thanks.

This is typically solved with the BeanItemContainer and setItemCaptionPropertyId:

http://vaadin.com/book/-/page/components.selecting.html

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.


com.vaadin.data.Property$ConversionException: java.lang.NoSuchMethodException: java.util.List.(java.lang.String)
	at com.vaadin.data.util.MethodProperty.convertValue(MethodProperty.java:697)
	at com.vaadin.data.util.MethodProperty.setValue(MethodProperty.java:666)
	at com.vaadin.ui.AbstractField.commit(AbstractField.java:241)
	at com.vaadin.ui.Form.commit(Form.java:339)
	at com.henkel.ccpwvaadin.view.UserFormView.buttonClick(UserFormView.java:47)