I’m currently on a project using Vaadin 6.8.1 + Spring 3, which is structured as a Vaadin interface that calls Spring services (and Hibernate behind).
Thanks to LazyQueryContainer (LQC), I could load from services my data and display it in Vaadin tables and comboboxes. At this point, everything is fine and great. However, I have a form which contains a combobox, with data from a LQC, that doesn’t select properly the correct item when the form’s setItemDataSource method is called.
For instance, my application manages a list of persons and companies in a database. There are 2 classes : Person and Company. And the relationship is as simple as a person is member of a company. So, the class Person has a field company of type Company.
Now, I have a Vaadin Form that manages a Person. And in this form is a combobox that displays all companies in the database, and the selected company is the company which the person is registered to.
Since my application is divided in services, I can’t use a JPAContainer or HibernateContainer to directly access my data. I’ve then choosed the LazyQueryContainer with its AbstractBeanQuery. I created a datasource for the Person and Company classes, and they display properly in a table and comboboxes. The Vaadin Form displays also properly the Person’s String fields in the text inputs.
However, I wanted to manage the Company field with the combobox instead of the default textbox. So, I implemented a FormFieldFactory and binded the field to the combobox. There is indeed no more default company textbox, which means the binding is working, but the selected value in the combobox is blank (null).
I implemented the equals and hashcode methods in the Company class, but it didn’t change anything. I thought also that I should load all the data in the combobox (since the number of items is low) but I don’t know how to get manually an object from the LQC object. And without source code, there’s no way to debug.
Any help would be very welcome.
Thanks.
I think you issue is that the
LazyQueryContaineris usingLongas item ID’s but the Vaadin form is trying to set yourCompanyas the combo box value. Since this id (theCompanyinstance) is not part of theLazyQueryContainerid list the selection remains null.You need to find out first the id of you
Companythat theLazyQueryContainerassigned to it, then set that value to the combo box. You will also need to create a custom field and subclass theComboBoxso you can handle thesetValuewhen it’s called by the form.Side Note: The Vaadin
BeanItemContaineruses your JavaBean as it’s item id. This is whymyCombo.setValue (myCompany)works.