GWT SuggestBox未在ValueChangeHandler上返回正确的值

时间:2016-03-19 08:53:06

标签: java gwt

我有一个GWT SuggestBox。当我选择一个项目时,我想从数据库中选择项目。我的代码是:

suggestionBoxScoutNumber.addValueChangeHandler(new ValueChangeHandler<String>() {
            public void onValueChange(ValueChangeEvent<String> event) {
                if (suggestionBoxScoutNumber.getText().length() != 0) {
                    //Look for Youth Member and display details if found 
                    // and error message if not found.
                    suggestionBoxScoutNumber.setStyleName("gwt-TextBox");
                    Window.alert("suggestionBoxScoutNumber.getText() = " + suggestionBoxScoutNumber.getText());
                    AsyncCallback<YthMmbrSectDtls> callback = new GetYMHandler<YthMmbrSectDtls>(EditYouthMemberView.this);
                    rpc.getYouthMemberSection(accountId, null, null, suggestionBoxScoutNumber.getText(), callback);
                }else{
                    suggestionBoxScoutNumber.setStyleName("gwt-TextBox");
                }
            }
        });

当我进入&#34; 1&#34;价值观&#34; 123&#34;和&#34; 912234&#34;显示。我选择&#34; 123&#34;和#34; Window.alert&#34;显示&#34; 1&#34;而不是&#34; 123&#34;因此,我选择的值不喜欢数据库。

1 个答案:

答案 0 :(得分:0)

使用getValue(),而不是getText()