error returning list from method

0 views
Skip to first unread message

ifrias

unread,
Feb 5, 2008, 7:32:49 AM2/5/08
to Google Web Toolkit
Hi there !
I have the following method :

public List getListaDepartamentosProjectoFromBD(final String
tipoElemento)
{

static List lista = new ArrayList();
AsyncCallback callback = new AsyncCallback() {

public void onFailure(Throwable arg0) {
add(new HTML("Erro ao obter lista de Departamentos/
Projectos"));
}

public void onSuccess(Object arg0) {

if(arg0==null)
Window.alert("Erro ao obter lista de departamentos/
projectos");
else{
lista = (List) arg0;
}
};


GWTServiceClass.getService().getListaDepartamentosProjectos(tipoElemento,
callback);
return lista
}

I want to know if it is possible to do what I am doing in the
code ...Returning a list from inside a async. call ...The Debug shows
me that after calling this method, the List returned has the value
"null" .
I have tried to use a global variable/field, instead of this
approach , but it was useless, the value remained null ...
Any ideas ?

Isaac Truett

unread,
Feb 5, 2008, 8:29:45 AM2/5/08
to Google-We...@googlegroups.com
You're not quite getting the "asynchronous callback" concept.
onSuccess() won't be called until after
getListaDepartamentosProjectoFromBD() has returned. You're just going
to have to wait for onSuccess() to be called and use the list there.

ifrias

unread,
Feb 5, 2008, 9:33:43 AM2/5/08
to Google Web Toolkit
I was trying to separate things . What I was trying to do was :

public class DadosNovaRequisicao implements VerticalPanel{



}

On 5 Fev, 13:29, "Isaac Truett" <itru...@gmail.com> wrote:
> You're not quite getting the "asynchronous callback" concept.
> onSuccess() won't be called until after
> getListaDepartamentosProjectoFromBD() has returned. You're just going
> to have to wait for onSuccess() to be called and use the list there.
>

ifrias

unread,
Feb 5, 2008, 9:44:23 AM2/5/08
to Google Web Toolkit
Hi Isaac ! I was doing the things as you've just said . I was filling
a table inside onSuccess() method and it worked well ...
I was trying to separate things . What I was trying to do was :

public class DadosNovaRequisicao implements VerticalPanel{

private FlexTable tabela;
List listaProdutos;


public DadosNovaRequisicao(){
listaProdutos = new ArrayList();
tabela = new FlexTable();
loadPainelNovaRequisicao();
add(tabela);

}

public void loadPainelNovaRequisicao(){

listaProdutos=getListaDepartamentosProjectoFromBD();
inicializarTabela(listaProdutos); // this will iterate over
listaProdutos, filling the table "tabela"
}
}

I've tried to put the things simple, my code isn't so simples as that
but you got the idea . Only with one method I could fetch all the data
from server, iterating over it in order to fill two or three different
tables with different data ....


On 5 Fev, 13:29, "Isaac Truett" <itru...@gmail.com> wrote:
> You're not quite getting the "asynchronous callback" concept.
> onSuccess() won't be called until after
> getListaDepartamentosProjectoFromBD() has returned. You're just going
> to have to wait for onSuccess() to be called and use the list there.
>

Isaac Truett

unread,
Feb 5, 2008, 9:50:53 AM2/5/08
to Google-We...@googlegroups.com
Right. You can't do that. That's not asynchronous.

You can do this, however:

public void onSuccess(Object arg0) {

if(arg0==null)
Window.alert("Erro ao obter lista de departamentos/
projectos");
else

inicializarTabela((List) arg0);
}


That way inicializarTabela() doesn't get called until the RPC returns.

Reply all
Reply to author
Forward
0 new messages