Sign In!
|
New User?Signup Now!
|
Forgot password?
Source Code 4 you
Home
Create Forum Topic
Check WebSite Rank
Publish Articles
UV Web Booster
Contact
Forum Type
Search Engine
.Net C# VB F# VC++
MonoPoject
Java J2EE
Zand Php Cake Php
Oracle Database Server
Mysql Database Server
DB2 Database Server
MSSql Databse Server
Javascript Ajax
Html Xml Xhtml
C Programming
C++ Programming
D Programming
CGI Programming
Perl Programming
Cobol Programming
Pascal Programming
Ruby Programming
Drupal Programming
Automobile
Software Testing
Linux Unix Mac Sun OS
Embedded Systems
Mainframe
IC Microcircuit Chip
Electronics Electrical
Hardware Netwarking
SAP ERP
Logical Reasoning
Human Resources
Science
Agriculture
Accounting
History
Pharmaceutical
Other Topic
Javascript Ajax
Posted by :
Dale
conversion to JavaScriptObject fails with cross site communication
I am creating my first GWT app and have hit a snag. I suspect that the
problem is one things below. I can see in the server logs that the
server returns ok.
This is the method that fails, there is no error ... that I can
see :)
private final native JsArray<BasicComputerInfo> asBasicComputerInfo
(JavaScriptObject jso) /*-{
return json;
}-*/;
I am calling it in the handleJsonResonse method and execution never
makes it to the UpdateDetailPanel Method.
public void handleJsonResponse(JavaScriptObject jso) {
if (jso == null) {
displayError("Couldn't retrieve JSON");
return;
}
updateDetailPanel(asBasicComputerInfo (jso));//<--After the
breakpoint here it never gets to updateDetailPanel
}
This is the response from the server looks like this when I get it
from a browser.
callback0(
{
"LastBootTime": "7/27/2009 8:46:25 AM",
"UserName": "aUser",
"OS": "xp",
"OSVersion": "5.1.2600",
"BuildDate": "5/6/2008 3:18:06 PM",
"RAM": "1063329792",
"HDCapasity": "26000076800",
"HDFree": "7487799296",
"NumProcessors": "1",
"PowerState": "Unknown",
"Site": "NA",
"Office": "NA",
"IPAddress": "NA",
"IPAddress": "Dell Inc.",
"Model": "OptiPlex GX620"
}
);
here is the BasicComputerInfo Class:
public class BasicComputerInfo extends JavaScriptObject {
protected BasicComputerInfo(){}
// JSNI methods to get stock data.
public final native String LastBootTime() /*-{ return
this.LastBootTime; }-*/;
public final native String UserName() /*-{ return this.UserName; }-
*/;
public final native String OS() /*-{ return this.OS; }-*/;
public final native String OSVersion() /*-{ return
this.OSVersion; }-*/;
public final native String BuildDate() /*-{ return
this.BuildDate; }-*/;
public final native int RAM() /*-{ return this.RAM; }-*/;
public final native Long HDCapasity() /*-{ return
this.HDCapasity; }-*/;
public final native Long HDFree() /*-{ return this.HDFree; }-*/;
public final native int NumProcessors() /*-{ return
this.NumProcessors; }-*/;
public final native String PowerState() /*-{ return
this.PowerState; }-*/;
public final native String Site() /*-{ return this.Site; }-*/;
public final native String Office() /*-{ return this.Office; }-*/;
public final native String IPAddress() /*-{ return
this.IPAddress; }-*/;
public final native String Manufacturer() /*-{ return
this.Manufacturer; }-*/;
public final native String Model() /*-{ return this.Model; }-*/;
}
Posted by :
Adam T
Re : conversion to JavaScriptObject fails with cross site communication
Hi Dale,
Could be a couple of things...
1) Your asBasicComputerInfo() method takes a variable "jso" and you
try and return a reference to a variable "json" - though maybe that's
just a typo in your message?
2) Your JSON response from server doesn't appear to be an array, so
ignoring any potential typo above, your asBasicComputerInfo() could be
failing when trying to "cast" a simple JavaScriptObject into a JsArray
- I'd suggest either returning an array from the server, or altering
your code so you don't use a JsArray.
Also, the data in your JSON is all strings, therefore methods like
public final native int RAM() will possibly fail later in your code -
you could create a new method in the BasicComputerInfo class that does
the conversion for you, e.g. public int getRAM(){Integer.parseInt(RAM
());} and change RAM() to return the String in the JSON.
Hope some of that helps!
If you have the better reply, then send it to us. We will display your reply after the approval.
Name :
Email Id :
Reply :