Important Notice - Forums is archived
To simplify things and help our users to be more productive, we have archived the current forum and focus our efforts on helping developers on Stack Overflow. You can post new questions on Stack Overflow or join our Discord channel.

Vaadin lets you build secure, UX-first PWAs entirely in Java.
Free ebook & tutorial.
pre-selected value in combobox not working
I'm showing a collection of beans in a combobox.
When creating the combobox, I want to preselect the previously saved selection. This bean (called "selectedBean" in the example below) is retrieved in a different hibernate-transaction than the bean-collection and therefore is not the same instance as the matching object in the collection.
I implemented the equals-method for Type "MyBeanType" and expected this to work:
List<MyBeanType> beans = myService.findAll();
myBeanContainer = new BeanItemContainer<MyBeanType>(MyBeanType.class);
myBeanContainer.addAll(beans);
view.setContainer(myBeanContainer); //view sets container and selected value on combobox
view.setSelectedBean(selectedBean);
But strangely no value is selected!
But when I change my code to this, it works:
List<MyBeanType> beans = myService.findAll();
for (MyBeanType beanInCollection : beans) {
if (beanInCollection.equals(selectedBean))
selectedBean = beanInCollection;
}
myBeanContainer = new BeanItemContainer<MyBeanType>(MyBeanType.class);
myBeanContainer.addAll(beans);
view.setContainer(myBeanContainer);
view.setSelectedBean(selectedBean);
The value in the collection corresponding "selectedBean" is selected correctly. That means my equals-method is working. But somehow it is not used by vaadin to identify the selected value. Why is that? What am I missing?
Thank you Anna, that was my problem.
simple question...simple answer.