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?

1

There are 1 answers

2
Constantino Cronemberger On BEST ANSWER

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:

private String test1 = null;
private String test2 = null;

private AsyncCallback<GetArticleResult> callback = new AsyncCallback<GetArticleResult>() {
    @Override
    public void onFailure(Throwable throwable) {
        Window.alert(throwable.getClass().getName() + " - " + throwable.getMessage());
    }

    @Override
    public void onSuccess(GetArticleResult s) {
        test1 = s.msg;
        test2 = "123";
        Window.alert(test1 + " - " + test2);
    }
};

private class MyValueChangeHandler implements ValueChangeHandler<String> {
    @Override
    public void onValueChange(ValueChangeEvent<String> stringValueChangeEvent) {
        Window.alert(test1 + " - " + test2);
    }
}

And my GetArticleResult is very simple:

public class GetArticleResult implements IsSerializable {

    public String msg;
}