Combobox - setPropertyDataSource - No Item Selected after Initialization

Hi,
I have made a form with a combobox.
The combobox gets its data via setContainerDataSource from a BeanItemContainer and the selection is bound to a property via setPropertyDataSource. Lets call the property it is bound to “state”.
When I select an item, everything works fine and after calling commit() the data is stored to the bean correctly, so there is a value now in the “state” property of the bean.
But when I recreate my form and the combobox is bound to a bean with “state” already set, the selection of the combobox is blank. I would expect, that the “state” stored in the bean would become the selection of the combobox.

Am I wrong with that?
Is there a smooth way to make a combobox which is bound to a property via setPropertyDataSource automatically select the correct item when the form is displayed?

Thanks in advance

Steve

When using BeanItemContainer, the bean itself is used as the item identifier. As long as you work with a fixed set of in-memory instances of the bean, there are no problems, but I assume you are e.g. restoring a new instance of the bean from the database or otherwise reconstructing it - it is not the same instance as the one you have in the container.

In that case, you need to implement suitable equals() and hashCode() methods on the bean - item identifiers should always have proper implementations of these methods that identify which instances should be treated as equivalent by BeanItemContainer. Most other containers do not use the POJOs themselves as identifiers, so this problem is most often seen with BeanItemContainer.

Hi,
and thank you very much for your explenation.
I already had implemented equals and hashcode in my beans but there was a little error in my equals function.
It took me some hours to find it out, as i thought the equals function is that last place to look for the error.

Works like a charm now.

Thanks.

Greetings,
Steve