ComboBox.select() not working when data source is SQLContainer

Hey guys,

So, I have a table that uses a SQLContainer as its data source. One of the table’s columns uses a ComboBox (generated with a table field factory), and that ComboBox also has a SQLContainer as its data source.

Now, everything works fine as far as committing values to the database, but when the table is first loaded, the ComboBox is not populated with the values that already exist in the table. Initially, I was led to believe that this is because a table field factory will wipe out the fields before the table is finished being generated, so I have a map of ComboBoxes and RowIds that I set later on, and this still doesn’t work.

Here’s some of what I have to (hopefully) explain it better…


table.setTableFieldFactory(new TableFieldFactory() {
            @Override
            public Field createField(Container container, Object itemId, Object propertyId, Component uiContext) {
                if (propertyId.equals("RESOURCE_NAME")) {
                    TableQuery q = new TableQuery("RESOURCES", pool);
                    q.setVersionColumn("RESOURCE_NAME");
                    SQLContainer resources = null;
                    try {
                        resources = new SQLContainer(q);
                    } catch (SQLException ex) {
                    }

                    ComboBox box = new ComboBox(null, resources);
                    box.setImmediate(true);
                    box.setNullSelectionAllowed(true);

                    mComboboxValueMap.put(box, new RowId(new Object[]{(String) taskBasedComponentContainer.getContainerProperty(itemId, "RESOURCE_NAME").getValue()}));

                    return box;
                } else {
                    ...
                }
            }
        });

And later…


        for (Map.Entry<ComboBox, Object> entry : mComboboxValueMap.entrySet()) {
            entry.getKey().select(entry.getValue());
        }

What’s baffling is that this all works completely fine if I use a collection of Strings as the ComboBox’s data source rather than a SQLContainer. I’m not sure why this isn’t working, though. Any help would be greatly appreciated.