SuggestBox in GWT - The correct way to create and populate.

Hi everyone, its been a while. Here, in this post, I will be discussing about creating, initializing and populating a suggestbox in gwt. Suggestbox is a text box or text area which displays a pre-configured set of selections that match users input.

Suggestbox is similar to an autocomplete search box. Each Suggestbox is associated with a single SuggestOracle. The SuggestOracle is used to provide a set of selections given a specific query string. SuggestBox uses a MultiWordSuggestOracle as its oracle.

Following are the steps to create and populate a SuggestBox and declaration of MultiSuggestOracle.

1) First step is to declare MultiSuggestOracle.


private final MultiWordSuggestOracle oracle = new MultiWordSuggestOracle();

2) Create SuggestBox

@UiField (provided = true
SuggestBox sbox = new SuggestBox(oracle);

The important thing to remember is to add (provided = true).

3) Populating the SuggestBox

private void populateSuggestBox() 
    {
List names = new ArrayList();

names.add("Sujith");
names.add"Mohan");
names.add("Justin");
names.add("Range");

          for (String val : names)
        {
            oracle.add(val);
           }
     }


This way a suggestbox can be created and populated in gwt.

Please feel free to express your doubts or comments. Thank you for reading the post.

Comments

Popular posts from this blog

Difference between "diff" and "sdiff" commands in Unix

Anonymous classes in C++