Vaadin 7 Combo Box - how to fill in the drop-down list when entering text?

I have an application in which there are editors for various database entries. These entries refer to each other. I am developing a new custom component that supports data, which is based on ComboBox:

public abstract class CustomDbLookupField<T> extends CustomField<T> implements Field<T> 

Here is what I want:

  • the component looks like a combo box (I could do it easily)
  • when the corresponding field has a row identifier value, then the component displays a textual representation of this reference record (I could do that too)
  • when the user starts typing in combobox, I want to search for keywords in the database and fill in the drop-down lists with these elements, and then
  • clear the combo box for it and select it from the results

I can not imagine the last two parts. I wanted to associate the listener with the event "text typed in the combo box", but I can not find any method for this. Moreover, I do not know how to get the text that has just been entered. I tried to do this:

cmb.addListener(com.vaadin.event.FieldEvents.TextChangeEvent.class,target, method);

but I don’t know what to pass to the target and method parameters.

+4
source share
1 answer

This is a good question and one that cannot be answered in a few sentences. I will try to give you a short answer in advance and try to tell you more about this later. I am currently hacking a small example demonstrating the function you want to achieve. But I need some more time. I will update my answer as soon as I get some results.

, , TextChangeEvents , , - . , , TextField. CustomField, . CustomField - . , TextChangeEvents .

, ComboBox. ComboBox ComboBox. Container, ComboBox. , ComboBox#getOptionsWithFilter(boolean) Container, .

. , , , ComboBox, , . ComboBox com.vaadin.ui.ComboBox.buildFilter(String, FilteringMode). Container.Filter, String com.vaadin.data.Container. . BeanItemContainer, de.oio.vaadin.SuggestingContainer.addFilter(Filter)

GitHub. , - .

+7

Source: https://habr.com/ru/post/1538388/


All Articles