Adding / modifying SuggestOracle after creating SuggestBox in GWT

All the information I can find for SuggestBox and MultiWordSuggestOracle suggests that the only way to set the oracle for the offer window is when it is created. I do not think this makes sense, because there is a default constructor that does not accept the oracle and creates it for you, supposedly empty. This is not good. What I'm looking for would be methods like setSuggestOracle(MultiWordSuggestOracle)or addToSuggestOracle(String), but I cannot find anything in the documentation suggesting how to do this.

+5
source share
1 answer

It doesn't seem like you can change the instance SuggestOracleafter creation SuggestBox, but you can access it with SuggetBox::getSuggestOracle(). From there, you will need to apply an implementation class to make changes to it; the base class SuggestOraclealone does not give anything. So something like:

SuggestOracle oracle = new MultiWordSuggestOracle();
SuggestBox box = new SuggestBox(oracle);

try {
  MultiWordSuggestOracle multiWordOracle = (MultiWordSuggestOracle)box.getOracle();
  multiWordOracle.add("This awesome suggestion.");
} catch (ClassCastException e ) {
  // the oracle was not what you thought it was
}
+7
source

All Articles