Search code examples
gwtsuggestbox

suggestBox: Suggestions aren't displayed as HTML anymore gwt 2.4 -->2.7


I am not familiar with gwt and I had to upgrade from gwt 2.4 to gwt 2.7.

I have a problem with a suggestBox item: i need to interpret HTML tag present in the MultiWordSuggestOracle:

I overrided isDisplayingStringHtml to be sure it was set to true:

private MultiWordSuggestOracle oracle = new MultiWordSuggestOracle() {
    @Override
    public boolean isDisplayStringHTML() {
        return true;
    }
};

Then I tried to insert this :

 private void initOracle() {

    String gogogogo= "<tt>####</tt>";
    HTML html = new HTML("<tt>####2</tt>");

    List<String> listeSuggeree = new ArrayList<String>();
    listeSuggeree.add("<HTML><div>#####</div></HTML>");
    listeSuggeree.add((gogogogo));
    listeSuggeree.add(html.getHTML());
    listeSuggeree.add("AAAAAH nothing work");

    oracle.addAll(listeSuggeree);
    oracle.setDefaultSuggestionsFromText(listeSuggeree);

HTML problem

All worked perfectly on gwt 2.4 and I didn't find a way to interpret this HTML on gwt 2.7.0, can you help me?


Solution

  • You should use MultiWordSuggestion.

    The constructor takes two parameters:

    replacementString - the string to enter into the SuggestBox's text box if the suggestion is chosen

    displayString - the display string

    Basically, displayString is shown in the list, replacementString is shown in the TextBox after selection.

    So, here is the proper way to prepare your suggestion list:

    List<Suggestion> listeSuggeree = new ArrayList<Suggestion>();
    listeSuggeree.add(new MultiWordSuggestOracle.MultiWordSuggestion("bold replacement", "<b>bold</b>"));
    listeSuggeree.add(new MultiWordSuggestOracle.MultiWordSuggestion("italic replacement", "<i>italic</i>"));
    listeSuggeree.add(new MultiWordSuggestOracle.MultiWordSuggestion("underline replacement", "<u>underline</u>"));
    listeSuggeree.add(new MultiWordSuggestOracle.MultiWordSuggestion("SUCCESS!", "All works!"));
    
    oracle.setDefaultSuggestions(listeSuggeree);
    

    And the output is:

    enter image description here

    BTW: isDisplayStringHTML is true by default.