13

I've defined a suggestbox in UIBinder, and I need to dynamically set its SuggestOracle. All the examples I've seen show that you can only define the suggestoracle at instantiation, but I need to define this AFTER the fact. Is there a way to do this?

Thanks!

Rob
  • 479
  • 8
  • 16
  • 1
    Found the answer - Create the suggestbox myself in the constructor passing in a blank suggestoracle, then manipulate the suggestoracle LATER dynamically: public MultiWordSuggestOracle oracleSuggestions = new MultiWordSuggestOracle(); public ucMyControl() { txtName = new SuggestBox(oracleSuggestions); initWidget(uiBinder.createAndBindUi(this)); } then later I could call this code: oracleSuggestions.clear(); for(int i=0; i – Rob Aug 22 '11 at 17:19
  • 4
    Put the answer in an answer, instead of a comment, please. – Jason Terk Aug 22 '11 at 20:45
  • 1
    I found that the way which the questioner stated is not enough. 1 more line of code is needed. You can find the whole answer in http://blog.jeffdouglas.com/2010/02/11/uibinder-with-suggestbox-multiwordsuggestoracle/ – John Hwang Feb 18 '12 at 12:27

2 Answers2

10

Use the method getSuggestOracle at SuggestBox to get the oracle. By default, it's from type MultiWordSuggestOracle. Then, just add the words you want:

MultiWordSuggestOracle orcl = (MultiWordSuggestOracle) suggestBox.getSuggestOracle();
orcl.addAll(words);
Italo Borssatto
  • 15,044
  • 7
  • 62
  • 88
0

As italo said, get the instance of SuggestOracle with getSuggestOracle(), then you can do a orcl.clear() to clean all the contents and finally addAll().

You can also check out this example that shows a SuggestBox (models) that depends on the selected value on another main SuggestBox (car brands).

http://siempredesdeelcurro.blogspot.com.es/2013/05/simplest-example-of-gwt-with-eclipse.html

Miguel Rivero
  • 1,436
  • 14
  • 11