English 中文(简体)
如何收集一些不合时代的要求?
原标题:How to collect a number of asynchronous callbacks?

是否有任何技术来收集一些高压服务反馈结果?

我有一个用于制造新物体或旧物体的方言窗口。 这些物体多次提到其他物体。 因此,当用户制造或编辑某一物体时,他可以在清单Box中选取一个物体。

public class School {
    private String name;
    private String address;
}

public class Car {
    private String model;
    private String type;
}

public class Person {
    private String firstName;
    private String lastName;
    private School school;
    private Car firstCar;
}

当方言窗口出现在屏幕上时,它应当要求所有参考资料领域的所有现有价值。 这些数值通过高压体向AsyncCallback索取,因此我可以逐一处理。

service.getAllSchools(new AsyncCallback<List<School>>() {
    @Override
    public void onSuccess(List<School> result) {
        fillSchoolListBox(result);
    }

    @Override
    public void onFailure(Throwable caught) {
        Window.alert("ups...");
    }
});
...
service.getAllSchools(new AsyncCallback<List<Car>>() {
    @Override
    public void onSuccess(List<Car> result) {
        fillCarListBox(result);
    }

    @Override
    public void onFailure(Throwable caught) {
        Window.alert("ups...");
    }
});

How to get all result in one place? Thanks.

最佳回答

最好的解决办法是指挥官Patter和Igorbel说,但如果你是开端人,你可以设计例如Bean集装箱,这些集装箱只包含必须经请求运输的豆类。

For example:

public class BeanContainer{
    private ArrayList<School> schools = new ArrayList<School>();
    private ArrayList<Car> cars = new ArrayList<Car>;
    private ArrayList<Person> people = ArrayList<Person>();

public void addSchool(School school){
    this.schools.add(school);
}

public void addSchoolCollection(ArrayList<School> schools){
    this.schools.add(schools);
}

public ArrayList<School> getSchoolCollection(){
    return schools;
}

...

}

问题回答

为什么不要求你建立一种新的服务方法,从而把所有数据归来?

采用这种方法只能指所有其他方法。 你们必须收集所有必要的数据,并作为单一结果予以退回。 你们如何处理这一问题的一个例子:

在服务实施方面:

@Override
public Data getAllData(){

    List<Cars> cars = this.getAllCars();
    List<School> schools = this.getAllSchools();

    return new Data(cars, schools);
}

那么,你可以采用这样的方法:

service.getAllData(new AsyncCallback<Data data>() {
    @Override
    public void onSuccess(Data data) {
        fillCarListBox(data.getCars());
        fillSchoolListBox(data.getSchools());
    }

    @Override
    public void onFailure(Throwable caught) {
        Window.alert("Pogreska...");
    }
});

采用这种办法,你将服务数量降至最低。 这不仅产生了更可读的法典,而且通常会加快你的客户。 你们应始终努力尽量减少服务电话的数量,最好是只打一个电话。

关于收集一些同步呼吁的较为一般性的问题,一个很好的办法是使用<>共同和模式。 Gwt 遥控行动是一个图书馆,它提供实施上述模式,以开展PC电话:

http://code.google.com/p/gwt-remote-action/"rel=“nofollow noreferer”>http://code.google.com/p/gwt-remote-action/





相关问题
Spring Properties File

Hi have this j2ee web application developed using spring framework. I have a problem with rendering mnessages in nihongo characters from the properties file. I tried converting the file to ascii using ...

Logging a global ID in multiple components

I have a system which contains multiple applications connected together using JMS and Spring Integration. Messages get sent along a chain of applications. [App A] -> [App B] -> [App C] We set a ...

Java Library Size

If I m given two Java Libraries in Jar format, 1 having no bells and whistles, and the other having lots of them that will mostly go unused.... my question is: How will the larger, mostly unused ...

How to get the Array Class for a given Class in Java?

I have a Class variable that holds a certain type and I need to get a variable that holds the corresponding array class. The best I could come up with is this: Class arrayOfFooClass = java.lang....

SQLite , Derby vs file system

I m working on a Java desktop application that reads and writes from/to different files. I think a better solution would be to replace the file system by a SQLite database. How hard is it to migrate ...

热门标签