What is the Suggestion Box?

The Suggestion Box is a subcalss of the Combo Box. The difference between these two components is that the suggestion box allows loading data on text change. The similar component exists in the standard GWT library, but it's rather complicated. So this widget is a simple alternative to this widget.

[top]


What's a difference between ComboBoxDataModel and SuggestionBoxDataModel?

As well as combo boxes the Suggestion Box widget requires data model (see also this sample). But to load values for suggestion it needs a special callback interface that is invoked on text change. This interface is org.gwt.advanced.client.ui.SuggestionBoxListener. You can implement it and add into the Suggestio Box.

But more it's comfortable and effective if you use SuggestionBoxDataModel insted. This model allows define a custom list callback handler and automatically invokes it if necessary. The next sample illustrates how it can be done.

SuggestionBoxDataModel model = new SuggestionBoxDataModel(new MyListCallbackHandler());
SuggestionBox suggestionBox = new SuggestionBox(5);
//minimal number of symbols required to invoke the handler
suggestionBox.setModel(model);// apply the model (the hadler will be invoked automatically

Note that you don't have to fill the model with values before you apply it. MyListCallbackHandler will do it when the text field of the widget contains 5 or greater symbols. MyListCallbackhandler must implement the org.gwt.advanced.client.datamodel.ListCallbackHandler interface.

[top]


Can I use ComboBoxDataModel in SuggestionBoxes?

Yes, but note that in this case this widget will work as a simple Combo Box.

[top]


Is it possible to create a grid cell that contains a SuggestionBox?

There is no a special cell class for this kind of widgets. You can use ComboBoxCell instead. See this answer for additional details.

[top]


Does the SuggestionBox allow choosing an item using a keyboard?

SuggestionBox extends the ComboBox class and therefore supports all features of the superclass including keyboard events handling. See this topic for details.

[top]