Tomek
17 Oct 2009, 1:54 AM
Hello guys,
I'm writing my first project in Ext GWT and I've got the following
problem:
I want to load XML file and save it to a local String variable.
public class XmlFile {
String temp;
public void greetServer() {
RequestBuilder requestBuilder = new RequestBuilder
(RequestBuilder.GET, "Test.gwt.xml");
try {
requestBuilder.sendRequest(null,new RequestCallback() {
@Override
public void onResponseReceived(Request request, Response response)
{
if (response.getStatusCode()==200)
{
temp=response.getText();
System.out.println(temp); //HERE OK
}
}
@Override
public void onError(Request request, Throwable exception) {
Window.alert(exception.getMessage().toString());
}
});
} catch (Exception ex) {
Window.alert(ex.getMessage().toString());
}
}
System.out.println(temp); //HERE ALWAYS NULL
}
I have to save loaded file to "temp" variable because I have to do
some other things with it in other classes. If I do it this way my
"temp" varaible is always null outside "onResponseReceived" function.
I've searched the Internet and found that it's because requestbuilder
is asynchronous and I should "make callback of this function". How can
I do that?
I'm writing my first project in Ext GWT and I've got the following
problem:
I want to load XML file and save it to a local String variable.
public class XmlFile {
String temp;
public void greetServer() {
RequestBuilder requestBuilder = new RequestBuilder
(RequestBuilder.GET, "Test.gwt.xml");
try {
requestBuilder.sendRequest(null,new RequestCallback() {
@Override
public void onResponseReceived(Request request, Response response)
{
if (response.getStatusCode()==200)
{
temp=response.getText();
System.out.println(temp); //HERE OK
}
}
@Override
public void onError(Request request, Throwable exception) {
Window.alert(exception.getMessage().toString());
}
});
} catch (Exception ex) {
Window.alert(ex.getMessage().toString());
}
}
System.out.println(temp); //HERE ALWAYS NULL
}
I have to save loaded file to "temp" variable because I have to do
some other things with it in other classes. If I do it this way my
"temp" varaible is always null outside "onResponseReceived" function.
I've searched the Internet and found that it's because requestbuilder
is asynchronous and I should "make callback of this function". How can
I do that?