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);
}
};
}
输出
setConnectionnull
connected null
onSuccesstrue
根据我的说法,输出应该是。
onSuccesstrue
setConnectiontrue
connected null
因为我创建了 LoginServer ;
对象,然后我调用方法 setConnection
,其中编写了 RPC 调用,该调用工作得很好。
OnSucces
将更改连接的值。
然后我调用了方法 getConnection
。
我也不明白为什么connected null
最佳答案
当/如果你让你的妻子/女朋友给你拿瓶啤酒时,你问她后的第二秒你手里就没有啤酒了,你可以继续观看比赛并使用react,你不会被屏蔽等待你的啤酒:这称为异步处理。
同样,在发送 RPC 调用后的第二秒,connection
仍然为 null
。
参见https://groups.google.com/d/msg/Google-Web-Toolkit/-soVdfMGug8/vRmqIcAZ5zsJ
关于java - GWT 中 RPC 调用后的流程?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9769081/