edwin
edwin

Reputation: 25

How to bind a LazyQueryContainer and a Combobox in a Form in Vaadin?

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.

Upvotes: 1

Views: 2008

Answers (1)

TRex
TRex

Reputation: 141

I think you issue is that the LazyQueryContainer is using Long as item ID's but the Vaadin form is trying to set your Company as the combo box value. Since this id (the Company instance) is not part of the LazyQueryContainer id list the selection remains null.

You need to find out first the id of you Company that the LazyQueryContainer assigned to it, then set that value to the combo box. You will also need to create a custom field and subclass the ComboBox so you can handle the setValue when it's called by the form.

Side Note: The Vaadin BeanItemContainer uses your JavaBean as it's item id. This is why myCombo.setValue (myCompany) works.

Upvotes: 1

Related Questions