Search code examples
comboboxautocompletegxt

Dynamic Autosuggest Combobox in GXT


Over the past 5 months we have been prototyping GWT and setting up the infrastructure. WE are using GXT for the widgets with MVP and Command Pattern implementations. However, we are currently looking to do a spike on a ComboBox with autosuggest from a live Database. I would like to do this in the framework of the MVP and Command pattern implementations. Any one out there have any ideas how to go about doing this?


Solution

  • I solved that using a generic DispatchDataProxy modelled over the Command Pattern. Thanks for the link, but GXT documentation leaves a lot to be desired, though the framework is really nice and cool.

    I will post the code here `public class DispatchDataProxy implements 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;
    }
    

    }`

    Hope its useful. Will appreciate some comments as well