gwt suggestionBox how to get text,value pairs in it

时光总嘲笑我的痴心妄想 提交于 2019-12-08 12:15:06

问题


i need a autosuggest combobox for an ambiguous list of strings. but everey string 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


回答1:


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();



来源:https://stackoverflow.com/questions/5661222/gwt-suggestionbox-how-to-get-text-value-pairs-in-it

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!