2

I am working with suggestion box in GWT but I stuck with a problem in which suggestionBox.showSuggestionList() not showing any results through focusHandler.

I have created a suggestion oracle and suggestBox as follows

MultiWordSuggestOracle mySuggestionOracle=new MultiWordSuggestOracle();
SuggestBox mySuggestBox=new SuggestBox(mySuggestionOracle);

then after when I got suggestionList values i.e. array of suggestions from somewhere I add those values to suggestion oracle like

for(String str : suggestionList){
    mySuggestionOracle.add(str);
}

Above code is written in view and I add FocusFandler to this suggestBox in presenter as,

view.mySuggestBox().getValueBox().addFocusHandler(new FocusHandler() {
        @Override
        public void onFocus(FocusEvent event) {
            view.mySuggestBox().setText(" ");
            view.mySuggestBox().showSuggestionList();
        }
    });

what can be issue, why this showSuggestionList() doesn't show any suggestions if we click in suggestBox.? but if we enter some text in suggestBox then it shows proper suggestions specific to input. i.e. if we enter a it shows all suggestions starts with a*.

Can someone help if had same scenario or some idea if I am wrong somewhere.?

1 Answer 1

2

First, to show default suggestions, you must set blank string as text in the SuggestBox before to call showSuggestionList method ( I suppose no string in suggestionList begins whith white space).

public void onFocus(FocusEvent event) {   
  view.mySuggestBox().setText("");  
  view.mySuggestBox().showSuggestionList(); 
}

Seconds, to display all suggestions, you must set them with setDefaultSuggestionsFromText method of MultiWordSuggestOracle object.

Example of constants

final static String[] SUGGESTIONS = {"alfred", "alicia", "bernard", "bruno", "bernadette"};
final static List<String> suggestionList = new ArrayList<String>(Arrays.asList(SUGGESTIONS));

Your initialization code :

for (String str : suggestionList) {
  mySuggestionOracle.add(str);
}
mySuggestionOracle.setDefaultSuggestionsFromText(suggestionList);


mySuggestBox = new SuggestBox(mySuggestionOracle);
mySuggestBox.setLimit(suggestionList.size());
1
  • and what if I create my custom oracle which will takes value from database through async call inside my oracle class.? Mar 18, 2016 at 7:29

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.