Wednesday, January 3, 2018

Re: Returning an array of objects to javascript via JsInterop - how?

Yes, that should work - a "java array" of js objects can be a js array. You could also use elemental2.core.JsArray<Product> instead if you wanted to be explicit in your Java code that you are dealing with a Java array.

On Tuesday, January 2, 2018 at 3:28:34 PM UTC-6, Power Droid wrote:
I have a class which is just a data storage object

public class Product{ 
int id;  
String name;
public Product()
{
}
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}  
 
}  

I have another class that will be used to process data and will have a method to return an array of Product objects based on the processing.

public class Processor {
public Product[] doStuff()
{
  ... 
}
}

My goal is to use JsInterop to make the doStuff() method available to other javascript on a site.

Is this as simple as putting the @JsType annotation at the top of both of these classes?  If so, does GWT handle the conversion of the array of Java Product objects into an array of javascript Product objects or is there something else that needs to be done?

--
You received this message because you are subscribed to the Google Groups "GWT Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to google-web-toolkit+unsubscribe@googlegroups.com.
To post to this group, send email to google-web-toolkit@googlegroups.com.
Visit this group at https://groups.google.com/group/google-web-toolkit.
For more options, visit https://groups.google.com/d/optout.

No comments:

Post a Comment