I have an array, premisasObtenidas, that I want to update with the contents that I get from a GWT AsyncCallback. The call works fine, and the code of onSuccess executes, but when I try to add what it returns to premisasObtenidas to return it on my getPremisasFromServer method I get a empty list.
How can I return from getPremisasFromServer, the List that I get from the success in the AsyncCallback?
private List<PremisaDTO> getPremisasFromServer() {
final List<PremisaDTO> premisasObtenidas = new ArrayList<PremisaDTO>();
//premisasObtenidas is declared on the outside class
myService.mostrarPremisas(
new AsyncCallback<List<PremisaDTO>>() {
public void onFailure(Throwable caught){
Window.alert("Falla al cargar premisas" + caught.getMessage());
}
public void onSuccess(List<PremisaDTO> premisasEnBD){
Window.alert("Exito al obtener premisas " + premisasEnBD.get(0).getTextoPremisa());
for (int i=0; i<premisasEnBD.size();i++){
PremisaDTO aux = new PremisaDTO();
aux.setId(premisasEnBD.get(i).getId());
aux.setTextoPremisa(premisasEnBD.get(i).getTextoPremisa());
premisasObtenidas.add(aux);
}
}
} );
return premisasObtenidas; //here premisasObtenidas has size 0
}