开发者

GWT MVP best practices to pass model data to the view

I'm implementing a GWT application using MVP pattern. In the presenter I'm sending the data (Model) from the RPC service to the view using setData(Object) method.

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 s开发者_Python百科ervices.


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.

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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜