简体   繁体   English

将模型数据传递到视图的GWT MVP最佳实践

[英]GWT MVP best practices to pass model data to the view

I'm implementing a GWT application using MVP pattern. 我正在使用MVP模式实现GWT应用程序。 In the presenter I'm sending the data (Model) from the RPC service to the view using setData(Object) method. 在演示者中,我正在使用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);
}

This would be perfect when passing only one Object or List from one service. 当仅从一项服务传递一个对象或列表时,这将是完美的。 What would be the best practice for sending more than one different object returned from different services. 发送从不同服务返回的多个对象的最佳实践是什么。

I wrote a simple class that keeps track of multiple service requests, and triggers a callback when all of them have completed. 我编写了一个简单的类,该类跟踪多个服务请求,并在所有请求完成后触发回调。 Then you can call display.setData(thing1, thing2, thing3) etc. I like this because then my display code can just display a single "loading..." message instead of having to worry about data arriving at different times. 然后,您可以调用display.setData(thing1,thing2,thing3)等。我喜欢这样,因为这样我的显示代码可以只显示一条“正在加载...”消息,而不必担心数据在不同时间到达。

Alternatively, if your display can understand that it might not get all of its data at once, you could call display.setDataType1(thing1) when you receive thing1, display.setDataType2(thing2) when you receive thing2, etc. 另外,如果您的显示器可以理解它可能无法一次获取所有数据,则可以在收到thing1时调用display.setDataType1(thing1),在收到thing2时调用display.setDataType2(thing2),依此类推。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM