Content
o Since we are using JSNI, it nees an object representation of data
o In our case, the message data. We need to create the message data object
o We create MessageData java code in the com.sample.client package
o Here is the code:
o In our case, the message data. We need to create the message data object
o We create MessageData java code in the com.sample.client package
o Here is the code:
public class MessageData extends JavaScriptObject {
protected MessageData() {
};
// JSNI methods to get stock data.
public final native String getMessage()
/*-{
return this.message;
}-*/;
}
o We need a protected constructor:
protected MessageData()
o We need to pass the data back as JSNI, hence we create this method:
public final native String getMessage()
/*-{
return this.message;
}-*/;
o /*-{return this.message;}-*/;
o This is the javascript object representation of our data, it is as if
we had an object:
class MessageData {
String message;
public String getMessage() {
}
}
o But, since we are extending the JavaScriptObject, we get for free:
String message;
public String getMessage() {
}
o /*-{return this.message;}-*/; replaces the latter