gwt suggestionBox how to get text,value pairs in it
i need a autosuggest combobox for an ambiguous list of strings. but everey st开发者_如何学运维ring has an unique id. this id is needed to know what the user has selected (send id back to server and do something with it).
how to implement this with the gwt's auto-suggest-comboBox "suggestionBox". Is there a way to get an List of id->name pairs (like with listBox.addItem(String name, String value)) into the suggestionBox? probably by overwriting suggestionOracle? (how to get the selected id of the selected name?)
or is this usecase better be implemented by another gwt widget?
thx in advance
Yep, you want to subclass SuggestionOracle. You also want to subclass Suggestion, to something that can hold the id you need.
public class StringWithIdSuggestion implements Suggestion {
Long id;
String string;
@Override public String getDisplayString(){
return string;
}
@Override public String getReplacementString() {
return string;
}
public Long getId() {
return id;
}
}
Then your suggestion oracle will give StringWithIdSuggestion instances, which you can cast for access to getId();
精彩评论