I found this very weird behavior in Gwt.
I have a simple TestPresenter.java that have 2 buttons. Button 1 get data from DB and return value via Asyncallback method. Button 2 is to retrieve that value from a private inner class.
private String test1;
private String test2;
private AsyncCallback<GetArticleResult> getArticleCallback=new AsyncCallback<GetArticleResult>(){
@Override
public void onFailure(Throwable caught) {
// TODO Auto-generated method stub
loadingPresenter.hide();
}
@Override
public void onSuccess(GetArticleResult result) {
test1=result.getVal();
test2="123";
}
};
private class InlineHTMLContextMenuHandler implements ContextMenuHandler {
@Override
public void onContextMenu(ContextMenuEvent event) {
System.out.println(test1);
System.out.println(test2);
}
}
Now, I click the Button 1 first & it get Data from DB, then I click the button 2. Then I get the output: test1=Null; test2="123";
when debugging the test1
show real value, not null
. For test1
variable, If I access it from a method normally then it will be fine but if accessing it from private inner class then I can't get its value.
What wrong? This so weird?
I did a test with GWT 2.5.1 and the problem did not happen. Most likely your problem is in the class GetArticleResult.
Here is the code I used:
And my GetArticleResult is very simple: