Re: loading variable from native method

2009-06-22 Thread daim

her's my problem:

JsArrayOverlayData db = new DatenbankOverlayData(data.php);
if(db.getData() == null)
   System.err.println(getData() is null!);

and everytime i get: getData() is null!


her's my class:

public class DatenbankT extends JavaScriptObject
{
private String phpURL = null;
private RequestBuilder requestBuilder = null;
private JsArrayT dataArray = null;

public Datenbank(String phpFile)
{
phpURL = GWT.getModuleBaseURL() + ../ + phpFile;
requestBuilder = new RequestBuilder(RequestBuilder.GET, phpURL);

request();
}

public JsArrayT getData()
{
return dataArray;
}

private final native JsArrayT asArrayOfData(String json)
/*-{
 return eval(json);
}-*/;

private void request()
{
try
{
requestBuilder.sendRequest(null, new RequestCallback()
{
public void onError(Request request, Throwable 
exception)
{
message.reportError(Couldn't retrieve 
JSON);
}

public void onResponseReceived(Request request, 
Response response)
{
if (200 == response.getStatusCode())
  dataArray =
asArrayOfData(response.getText());
}
});
}
catch (RequestException e)
{
message.reportError(Couldn't retrieve JSON);
}
}
}

need help :(


On 19 Jun., 09:20, daim robin@googlemail.com wrote:
 hi,

 im trying to set the membervariabledataArray with the eval(json)
 result, but dataArray stays always null :(

 //here is my membervariable
 private JsArrayT dataArray = null;

 //here is thenativemethod
 private finalnativevoid asArrayOfData(String json)
 /*-{
            th...@de.rob1n.gruen.client.datenbank::dataArray = eval
 (json);

 }-*/;

 how to do that?!

 thanks
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
Google Web Toolkit group.
To post to this group, send email to Google-Web-Toolkit@googlegroups.com
To unsubscribe from this group, send email to 
google-web-toolkit+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/Google-Web-Toolkit?hl=en
-~--~~~~--~~--~--~---



Re: loading variable from native method

2009-06-22 Thread waf

Hi daim

You are not taking into account the asynchronious
nature of the request that you use to initialize the
Databank.dataArray. When the constructor returns
dataArray is null until request completes so
prepature access to the dataArray gives you null.

--
waf

--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
Google Web Toolkit group.
To post to this group, send email to Google-Web-Toolkit@googlegroups.com
To unsubscribe from this group, send email to 
google-web-toolkit+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/Google-Web-Toolkit?hl=en
-~--~~~~--~~--~--~---