Reload ComboBox List while typing

Hi

I got a ComboBox and want to reload (from db) the set of entries in the dropdown list while typing in the text field of the ComboBox. I always got the exception:
java.lang.IllegalStateException: A connector should not be marked as dirty while a response is being written.
I tried to lock the session (getUI().getSession().getLockInstance().lock();), but it didn’t help.

Is it possible to dynamically set/load the selection list of a ComboBox?

Cheers
Stefan

Hello,

Try wrapping the update method into UI.getCurrent().access().

This works. Thank you.
But, the intension is to get an instant search field (same as Google search field). While the user is typing, a list of new pattern/words is proposed.
I use a ComboBox, not sure whether it’s the right approach. Because now, the content of the list is the one from the previous search. For instance, when I type “aa”, I got results that starts with “a”. When I type another “a” (so it’s “aaa” now), I got reults starting with “aa”. Since the result list is correct. I use setContainerDataSource. I got the impression, that the ComboBox is refreshed before the new list is populated.
My entry point to react on typing is the buildFilter method, wich I override. I didn’t find another trigger point.

Well, new container is not seen in the UI until next user action, that’s how it works by default if you’re in a background thread.
If your DB calls are short, you can try doing them on UI thread, then you don’t need UI.access and you’ll see updated content immediately.
Otherwise you can enable Push (@Push) or polling (UI.getCurrent().setPollingInterval()), which would refresh the UI.


Lazy, suggesting combobox
may be useful.

@Michael: Tahnks for our answer. The DB call is short enough, so I’d like to try an update in the UI thread. But that brings me back to the beginning of this thread:
“java.lang.IllegalStateException: A connector should not be marked as dirty while a response is being written”
Is it possible to update the ComboBox list while the user is typing?
The push/poll stuff doesn’t sound suitable for this problem.

@Agata: I’ll take a closer look to that, thanks.