I can\'t understand why the code after the gwt rpc AsyncCallback will not be executed?
for example I have the interface AppService extends RemoteService, So I\'ll have A
You should understand the nature of the Async call. The programm execution will not be waiting when you call service.getCurrentUser
. The programm will continue to the next line (boolean isAdmin = false
) and it will be true for some time that (currentUser == null)
until method getCurrentUser
is executing. You should move not executed block of code into the onSuccess
handler
This example should look something like this:
service.getCurrentUser(new AsyncCallback(){
public void onFailure(Throwable caught) {
}
public void onSuccess(Employee result) {
currentUser = result;
if (currentUser != null) {
if (currentUser.getUserRole().equals("ROLE_ADMIN") ||
currentUser.getUserRole().equals("ROLE_MANAGER")) {
isAdmin = true;
}
}
}
});
I assume that currentUser and isAdmin are class fields, but not local variables. If isAdmin
is local than you can wrap this variable into the final array: final boolean[] isAdmin = new boolean[1]
and call it like isAdmin[0]