Search code examples
javagwtasynccallback

Problems with AsyncCallback in GWT


Hi, I'm beginner in gwt programming and I have depared with a problem with this AsyncCallback well my code is like this:

But when I call this method it returns the list before the Callback can make up the list.

`public static ArrayList<Appointment> build(Usuario user,AppointmentStyle[] styles) {
        final ArrayList<Appointment> list = new ArrayList<Appointment>();
        callback = new AsyncCallback<List<Compromisso>>() {

            @Override
            public void onFailure(Throwable caught) {
                MessageBox.alert("Erro", "Contate o administrador", null);

            }

            @Override
            public void onSuccess(List<Compromisso> result) {
                compromissos = result;
            }

        };
        getServico().listCompromisso(user, callback);


        for (int i = 0; i < compromissos.size(); i++) {
            Date now = new Date();
            now.setDate(compromissos.get(i).getData().getDate());

            Date start = (Date) now.clone();
            int hour = compromissos.get(i).getHorai().getHours();
            int min = compromissos.get(i).getHorai().getMinutes();
            start.setHours(hour);
            start.setMinutes(min);

            Date end = (Date) now.clone();
            end.setHours(compromissos.get(i).getHoraf().getHours());
            end.setMinutes(compromissos.get(i).getHoraf().getMinutes());

            Appointment appt = new Appointment();
            appt.setStart(compromissos.get(i).getHorai());
            appt.setEnd(compromissos.get(i).getHoraf());

            if (compromissos.get(i).getPrivacidade().getCodigo() == "1") {
                appt.setTitle(compromissos.get(i).getTitulo());
                appt.setDescription(compromissos.get(i).getNota());
            } else if (compromissos.get(i).getPrivacidade().getCodigo() == "2") {
                appt.setTitle(compromissos.get(i).getTitulo());
                appt.setDescription("Dados n&atilde;o disponiveis.");
            } else {

                appt.setTitle("Ocupado");
                appt.setDescription("Dados n&atilde;o disponiveis.");
                appt.setStyle(AppointmentStyle.GREY);
            }
            if (compromissos.get(i).getPrioridade().getCodigo() == "1") {
                appt.setStyle(AppointmentStyle.RED);
            } else if (compromissos.get(i).getPrioridade().getCodigo() == "2") {
                appt.setStyle(AppointmentStyle.GREEN);
            } else if (compromissos.get(i).getPrioridade().getCodigo() == "3") {
                appt.setStyle(AppointmentStyle.GREEN);
            }
            list.add(appt);
        }

        return list;
    }`

What should i do ?


Solution

  • I solved the problem sending to the method the items aready load from DB thx to all.