如何使用GWT建议使用RPC框?

时间:2011-08-26 14:35:08

标签: gwt

但在具体要求中,我想使用GWT提供的建议框。我无法从DB获取所有字符串并存储在建议框中,因为它有16000条记录。所以我的要求是当用户输入3个字符时,我需要获得匹配3个字符的字符串(如搜索)。请建议我如何实现这个目标?

谢谢!

1 个答案:

答案 0 :(得分:4)

实现您自己的SuggestOracle,当被要求提供建议时,进行异步服务器调用而不是匹配内存中的字符串集:

public class MySuggestOracle extends SuggestOracle {
  public void requestSuggestions(SuggestOracle.Request suggestRequest,
                                 final SuggestOracle.Callback callback)
  {
    RequestBuilder rb =
      new RequestBuilder(RequestBuilder.GET,
                         "/suggestions?" + suggestRequest.getQuery());
    rb.sendRequest(null, new RequestCallback() {
      @Override
      public void onError(Request request, Throwable exception) {
        // Handle error
      }

      @Override
      public void onResponseReceived(Request rbRequest, Response response) {
        SuggestOracle.Response r = new SuggestOracle.Response();

        // Fill r based on suggestions in the response parameter.

        callback.onSuggestionsReady(suggestRequest, r);
      }
    });
}