Dynamic Autosuggest Combobox in GXT

江枫思渺然 提交于 2020-01-15 11:36:35

问题


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?


回答1:


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




回答2:


Have you looked here?

http://www.sencha.com/examples-2/explorer.html#advancedcombobox

They show something similar. The issue with GXT is you are better off using their DataProxy because you need to set a ModelData instance.




回答3:


I found solution for simple combo box, override getValue method:

    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;
            }
        };

    }

Now when you add to combo box default value (not defined in store) method getValue returns this value - not null.



来源:https://stackoverflow.com/questions/4025268/dynamic-autosuggest-combobox-in-gxt

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