Data from SQLContainer to Combobox?


What is the best or easiest way to get values from SQLContainer to Combobox?

FreeformQuery free = new FreeformQuery(queryString, connectionPool);
countryContainer = new SQLContainer(free);

Table countryTable = new Table(“countries”, dbHelper.getCountryContainer());

So what is the best way to populate combobox with that data and how?


FreeformQuery free = new FreeformQuery(queryString, connectionPool);
countryContainer = new SQLContainer(free);

I hope that it will be usefull :slight_smile:

I tried that already, but no success. I got that error message:

at com.vaadin.addon.sqlcontainer.RowId.toString(
at com.vaadin.ui.AbstractSelect.getItemCaption(
at com.vaadin.ui.Select.paintContent(
at com.vaadin.ui.ComboBox.paintContent(
at com.vaadin.ui.AbstractComponent.paint(
at com.vaadin.ui.AbstractOrderedLayout.paintContent(
at com.vaadin.ui.AbstractComponent.paint(
at com.vaadin.ui.TabSheet.paintContent(
at com.vaadin.ui.AbstractComponent.paint(
at com.vaadin.terminal.gwt.server.AbstractCommunicationManager.writeUidlResponce(
at com.vaadin.terminal.gwt.server.AbstractCommunicationManager.paintAfterVariableChanges(
at com.vaadin.terminal.gwt.server.AbstractCommunicationManager.doHandleUidlRequest(
at com.vaadin.terminal.gwt.server.CommunicationManager.handleUidlRequest(
at com.vaadin.terminal.gwt.server.AbstractApplicationServlet.service(
at javax.servlet.http.HttpServlet.service(

Data is like that if I populate table with it:

So have you an idea what is happening. I am too newbie with Vaadin so I have to ask. I tried just select countries in my select (only one column) but I got the same result :frowning:

Thanks for helping me!

What is the query queryString?

String queryString = “select * from CITY”;

I tried everything like select cityid from CITY, select * from countries etc. Everything is working fine with Table, but not in Combobox. BTW how can I get key/value pairs from SQLContainer?

PropertyIDs I can iterate like that, but can I have keys and values inside the container? I think that it is the another possibility to build working Combobox?
Collection propertyIds = countryContainer.getContainerPropertyIds();
Iterator iterator = propertyIds.iterator();
while (iterator.hasNext()) {

Thanks a lot to you!

I have no idea … sorry :confused:
I’ll give you an example of how i used the combobox with sqlcontainer, maybe it will help you.

This is my product Table in mySQL:

| id | name | value | year |

and this is the code to populate the combo:

try {
  String query1 = new String("SELECT * FROM product");
  FreeformQuery productFreeFormQuery = new FreeformQuery(query1, myConnection.getConnectionPool());
  productContainer = new SQLContainer(productFreeFormQuery);
} catch (SQLException e) {

   new Property.ValueChangeListener() {
    public void valueChange(ValueChangeEvent event) {
     Item item = productComboBox.getItem(productComboBox.getValue());
     String selectedProductString = item.getItemProperty("id").toString();
     getWindow().showNotification("Selected Item: " + selectedProductString);

In this way i see the column “name” in the combobox, but on click i select the value “id”.

ComboBox combobox = new ComboBox();
combobox.setItemCaptionPropertyId(“country”);---------------> I added this one and it worked, I have no idea what it is doing :slight_smile:

Thanks a lot for your help!! BTW could I ask you a little bit more :slight_smile:

I have a form where is about 8 fields, couple of comboboxes and 6 text fields. User is adding a new company to my system. What is the wisest way to make that kind of form?

Just new form and new text Fields and after submiting the form populate my compamyPOJO with my data field by field? There is nested pojos (companyPOJO includes AddressPOJO and AddressPOJO includes cityPOJO etc.)

basicInfoForm = new Form();
	TextField companyName = new TextField("Company name"); //This goes to companyPOJO and COMPANY-table
	TextField address = new TextField("Address");//This goes to AddressPOJO inside the CompanyPOJO and ADDRESS-table
	TextField zip = new TextField("Zip");//This goes to AddressPOJO inside the CompanyPOJO and ADDRESS-table
	ComboBox combobox = new ComboBox("Select country");
	basicInfoForm.addField("address", address);
	basicInfoForm.addField("zip", zip);
	basicInfoForm.addField("combobox", combobox);
	basicInfoForm.getLayout().addComponent(new TextField("TEST"));

	Button okbutton = new Button("OK", basicInfoForm, "commit");
	okbutton.addListener(new ClickListener() {....

When comminting that form, form is null. I don’t know how to use form.addField-method. I don’t know how to bind SQLContainer to Form, I don’t know how to bind one field to my CompanyPOJO’s field, for instance address etc.

Could you pls give me some example or explain what is the wisest way to do that. Another case is updating, then (I think) I have to bind updated fields to SQLContainer’s field or ComapnyPOJO’s fields and then I have no idea how to handle nested POJOs (CompanyPOJO-AddressPOJO).

Thank you very much!


Stumbled upon this thread when investigating a problem where the Combobox backed by a SQLContainer would not show the Item value.
The situation is that I have a Form, backed by an Item datasource. One of the Item properties is a Long called

The suppliers are loaded from the database via a SQLContainer.

If I want to edit the item, the Combobox is not showing the correct supplier. NB It correctly loads the suppliers from the database.
After some digging i found that this piece of code solves my problem.

Object data = materialItem.getItemProperty( Material.SUPPLIER_ID_DB ).getValue();
((com.vaadin.ui.ComboBox) getField( Material.SUPPLIER_ID_DB )).select(new RowId(new Object[] { data }));

Kind regards,

how to select value from combobox when it views SQLContainer data

SQLContainer container=null;
        TableQuery tq = new TableQuery(table, Db.pool);
        try {
            container= new SQLContainer(tq);
        } catch (SQLException e) {
            // TODO Auto-generated catch block
final ComboBox cm1 = new ComboBox("Salary Config");