ComboBox used for value suggestion and custom filtering

I need to implement ComboBox which will suggest values for user. I found there is build in functionality for value suggestion but there are some limitations for me:

  1. Items (suggested values) for ComboBox has to be constructed before ComboBox is created, so all values are kept in memory on server side all the time the ComboBox instance exists
  2. I need to limit count of suggested values, because it has no sense for user to scroll down in drop down list, it is easier for user to type one more character in a text box part of ComboBox

I found that ComboBox implementation uses internaly its public method getFilteredOptions() to obtain values for drop down list when necessary. So I created new class interited from ComboBox and override method getFilteredOptions(). I wanted to provide my own implementation for selecting suggested values there. I think overriding getFilteredOptions() is good place where to do this but I found this problem: I am not able to get text entered by user into ComboBox’s text part. There is private field filterstring inside ComboBox class but I found no way how to access this raw value entered by user (expect dangerous access of private field via reflection).

My questions are:
Is there any way how to get filterstring (raw value entered by user) from ComboBox?
Is there any other good control for implementing text box with suggestion drop down list like on google web site with customizable implementation of selection of suggested values?

Hi,

The API for ComboBox would really need some improvements to allow customizations like this, and it’s on the list, but no ETA yet.
Duplicating the class is one solutions, though obviously not a good one (almost like using reflect).

You could have a look at Sami’s Autocomplete component that is in the incubator - I have not tried it myself yet, but I understand it’s quite flexible.
http://dev.itmill.com/browser/incubator/AutoComplete
Actually, I see Sami is in our kitchen right now, so I’ll tell him to comment on this thread :slight_smile:

Best Regards,
Marc

back from the kitchen…

Yes, the AutoComplete component tries to solve same kind of a problem. It was designed for autocomplete in larger text fields and is triggered/opened using a key combination (by default ctrl-space).

The API is quite simple - just a single
interface
that you should implement to respond to user raw input.

And the limitations: I got a little bit stuck with the popup positioning. So, it is not implemented. The location of popup is now fixed and may not be very suitable for different sizes of editors.

Hope this helps. I leave you to decide whether it is suitable for your current app.

Thank you for the anwser. First I will try to use AutoComplete control and if AutoComlete will not meet my requirements I will try to find a way how to use standard GWT control SuggestBox.

If you need some (potentially simple) enhancements to the AutoComplete, please let me know. Maybe I can help. :slight_smile:

Well this thread is ancient history by now, but for the record it’s possible to create your own filterstring variable, by overriding changeVariables:

    @Override
    public void changeVariables(Object source, Map<String, Object> variables) {
        newFilter = (String) variables.get("filter");
        if (newFilter == null) {
            newFilter = "";
        }
        super.changeVariables(source, variables);
    }

newFilter can then be used in the overridden getFilteredOptions method.