【问题标题】:GWT MVP best practices to pass model data to the view将模型数据传递给视图的 GWT MVP 最佳实践
【发布时间】:2011-09-01 13:34:16
【问题描述】:

我正在使用 MVP 模式实现 GWT 应用程序。 在演示者中,我使用 setData(Object) 方法将数据(模型)从 RPC 服务发送到视图。

private void getmaterialTypes(final String formType) {
    new RPCCall<List<MaterialType>>() {

        public void onFailure(Throwable arg0) {
            Window.alert("Error : unsuccess...");
        }

        public void onSuccess(List<MaterialType> result) {
            display.setData(result, "MaterialType");
            Window.alert("Success Getting Material Types !");
        }

        @Override
        protected void callService(AsyncCallback<List<MaterialType>> cb) {
            materialTypeService.findMaterialTypesByFormType(formType, cb);
        }
    }.retry(3);
}

当仅从一项服务传递一个对象或列表时,这将是完美的。发送从不同服务返回的多个不同对象的最佳做法是什么。

【问题讨论】:

    标签: java gwt mvp


    【解决方案1】:

    我编写了一个简单的类来跟踪多个服务请求,并在所有请求都完成时触发回调。然后你可以调用 display.setData(thing1, thing2, thing3) 等。我喜欢这样,因为这样我的显示代码可以只显示一个“正在加载...”消息,而不必担心数据在不同时间到达。

    或者,如果您的显示器可以理解它可能不会一次获取所有数据,您可以在收到 thing1 时调用 display.setDataType1(thing1),在收到 thing2 时调用 display.setDataType2(thing2),等等。

    【讨论】:

    • 第一种方法似乎更好,因为它可以确保获取所有异步数据但是不清楚如何实现,请您提供示例或伪代码吗?
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2012-07-22
    • 2014-12-30
    • 2016-03-01
    • 1970-01-01
    • 1970-01-01
    • 2013-05-13
    • 1970-01-01
    相关资源
    最近更新 更多