Thursday, July 3, 2008

Google Web Toolkit - Suggest Box

There seems to be some confusion on the web about whether GWT supports an auto completion widget. I suspect this is because the first version of GWT didn't support it.

However 1.4 sure does, its called SuggestBox. SuggestBox takes a SuggestOracle that contains the data you want and is responsible for returning suggestions.

Here is an example of how to use it:


MultiWordSuggestOracle oracle = new MultiWordSuggestOracle();
oracle.add("foo");
oracle.add("bar");
oracle.add("baz");
oracle.add("toto");
oracle.add("tintin");

SuggestBox sb = new SuggestBox(oracle);

// Add it to the root panel.
RootPanel.get().add(sb);

3 comments:

Anonymous said...

Is there an open-source implementation of a sublclass that uses RPC for retrieving the list of possible values?

developer-resource said...

You can do that with GWT just as well.

You need to create your own Oracle which will run on the server and you return possible matches.

I'll write up a new post with an example of how to do that.

Eric Nguyen said...

Hey did you or anyone else you know of ever write up a dynamic suggestbox example like you mention here?