2010-10-26 26 views
1

在過去的5個月中,我們一直在GWT原型設置基礎設施。我們使用GXT作爲MVP和Command Pattern實現的小部件。但是,我們目前正在考慮在帶有自動建議功能的ComboBox上通過實時數據庫實現峯值。我想在MVP和Command模式實現的框架中做到這一點。任何一個有任何想法如何去做這件事?GXT中的Dynamic Autosuggest Combobox

回答

2

我解決了,使用通用的DispatchDataProxy模擬命令模式。感謝您的鏈接,但GXT文檔留下了很多希望,雖然框架非常好,很酷。

我將在這裏發佈的代碼`公共類DispatchDataProxy實現DataProxy> {

@Inject 
private DispatchAsync dispatch ;//= new StandardDispatchAsync(new DefaultExceptionHandler()); 

@Override 
public void load(DataReader<ListLoadResult<X>> reader, Object loadConfig, final AsyncCallback<ListLoadResult<X>> callback) { 
    if (loadConfig instanceof BasePagingLoadConfig) { 
     BasePagingLoadConfig a = (BasePagingLoadConfig) loadConfig; 
     Map<String, Object> map = a.getProperties(); 
     Object data = map.get("query"); 

     XCommand action = new XCommand(); 
     action.setX((String) data); 

     dispatch.execute(action, new AsyncCallback<XResult>() { 

      @Override 
      public void onFailure(Throwable arg0) { 
       //Log.debug("Some error:" + arg0.getMessage()); 
       callback.onFailure(arg0); 
      } 

      @Override 
      public void onSuccess(XResult arg0) { 
       ListLoadResult<X> list = arg0.getList(); 
       callback.onSuccess(list); 
      } 
     }); 
    } 
} 

public DispatchAsync getDispatch() { 
    return dispatch; 
} 

public void setDispatch(DispatchAsync dispatch) { 
    this.dispatch = dispatch; 
} 

}`

希望它是有用的。會明白一些意見以及

+1

+1對於窮人文檔... – Guillaume 2011-10-12 14:01:56

0

我發現簡單的組合框的解決方案,覆蓋getValue方法:

public SimpleComboBox<String> createEditableSimpleComboBox() { 
     return new SimpleComboBox<String>() { 

      @Override 
      public SimpleComboValue<String> getValue() { 
       SimpleComboValue<String> v = super.getValue(); 
       String raw = getRawValue(); 
       if ((v == null || v.getValue() == null) && raw != null && !raw.isEmpty()) { 
        v = new SimpleComboValue<String>(raw){ 
         private static final long serialVersionUID = 1L; 
        }; 
       } 
       return v; 
      } 
     }; 

    } 

現在,當您添加到組合框的默認值方法GetValue返回這個值(以店內沒有定義) - 不爲空。