GXT 中的动态自动建议组合框

发布于 2024-09-29 03:28:16 字数 152 浏览 1 评论 0原文

在过去的 5 个月里,我们一直在制作 GWT 原型并建立基础设施。我们将 GXT 用于具有 MVP 和命令模式实现的小部件。然而,我们目前正在寻求通过实时数据库的自动建议来对 ComboBox 进行峰值。我想在 MVP 和命令模式实现的框架中做到这一点。那里有人有任何想法如何去做这件事吗?

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?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

↘紸啶 2024-10-06 03:28:16

我使用基于命令模式建模的通用 DispatchDataProxy 解决了这个问题。感谢您提供的链接,但 GXT 文档还有很多不足之处,尽管该框架确实非常好而且很酷。

我将在这里发布代码 `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;
}

}`

希望有用。也会感谢一些评论

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

蓝颜夕 2024-10-06 03:28:16

你看过这里吗?

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

他们展示了类似的东西。 GXT 的问题是你最好使用他们的 DataProxy,因为你需要设置一个 ModelData 实例。

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.

灯下孤影 2024-10-06 03:28:16

我找到了简单组合框的解决方案,覆盖 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 方法返回该值 - 非空。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文