public Class GUi(){
// More Code
public void onClick(ClickEvent event) {
LoginServer loginServer =new LoginServer(getTextBoxUsername().getText(),getTextBoxPassword().getText());
loginServer.setConnection(connection);
connection=loginServer.getConnection();
System.out.println(" connected "+connection);
// More code
}
public class LoginServer {
// more code
public void setConnection(Boolean connection) {
String[] authentication = {username,password};
//RPC call
connectionService.connectionServer(authentication, callbackConnection);
System.out.println("setConnection" + connection);
}
public Boolean getConnection() {
return connection;
}
AsyncCallback callbackConnection = new AsyncCallback() {
public void onFailure(Throwable caught) {
// TODO Auto-generated method stub
connection=false;
}
public void onSuccess(Object result) {
connection=true;
System.out.println("onSuccess + connection);
}
};
}
Output
setConnectionnull
connected null
onSuccesstrue
According to Me the Output should be.
onSuccesstrue
setConnectiontrue
connected null
Because I made object of LoginServer ;
Then I call method setConnection
where there is RPC call written which is working perfectly fine.
OnSucces
will change the value of connection.
Then I called method getConnection
.
I also don't understand why connected null
When/if you ask your wife/girlfriend to bring you a beer, you don't have that beer in your hand the second after you asked her, and you can continue watching the match and reacting, you're not blocked waiting for your beer: that's called asynchronous processing.
Similarly, connection
is still null
the second after you send your RPC call.
See https://groups.google.com/d/msg/Google-Web-Toolkit/-soVdfMGug8/vRmqIcAZ5zsJ