ComboBox with many items - SQLContainer - A quick hack


i am using the ComboBox as a cross reference field that visualizes 0:1 references between database tables.

If you try to use the ComboBox for tables > 5.000 records, it will become pretty slow if you are using SQLContainer since the combo box tries to navigate to the page of the selected item. And the SQLContainer has to lookup for the index of the given item id.

So i did a hack that works really fine.

comboBox.setScrollToSelectedItem(false) will tell the combo box to stop scrolling to the record with the given id.
But then the combo box won’t show any result since the selection has to be part of its options.

OK, lets add the current value to the list of options (see code below) an everything works fine again!
For sure, the combo box does not scroll to the page with the selected record, but now it is pretty fast!

private static class ExtendedComboBox extends ComboBox {

	public ExtendedComboBox() {

	protected List<?> getOptionsWithFilter(boolean needNullSelectOption) {
		List<Object> options = (List<Object>) super

		if (getValue() != null) {
			options.add(0, getValue());

		return options;


That mostly works but one issue i had is how to do you select an item in the ComboBox in the first place. The only way I was able to make it work was brute force method. Obviously this will be completely non-performant with a large dataset:

				for(Object itemId :  organizations.getItemIds()) {
					Item item = organizations.getItem(itemId);
					Property property = item.getItemProperty("ID");
					if (organizationId.getValue().equals(property.getValue())) {"Selecting item: {}", property);

I tried using this method but it didn’t work: RowId(new Object[] { organizationId.getValue() }));

It does end up calling my query delegate getContainsRowQueryStatement() method and it returns true but the combobox stays empty.

Any ideas?