Search code examples
javagwttextboxsuggestbox

GWT-SuggestBox as a TextBox?


I currently have a GWT textbox class that I would like to use, and sometimes based on certain parameters, transform it(add the functionality) into a suggestbox. Is this possible?

I don't want to create a new type of widget because then i would loose all of the current functionality of my TextBox, which I only wish to add the feature of suggestbox too...sometimes.

Assuming this is possible how would I link the two together? I obviously cant just do:

myTextBox.add(mySuggestBox);

I realize I appear as a novice here, and I can assure you, that is the case :)

Thanks!


Solution

  • You can enhance any existing ValueBox<String> (note that TextBox extends it) with a SuggestBox, just use the appropriate constructor:

    TextBox textBox = new TextBox();
    MultiWordSuggestOracle oracle = new MultiWordSuggestOracle();
    
    SuggestBox suggestBox = new SuggestBox(oracle, textBox);
    

    Any handler previously added to the text box will work.