Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to create a JavaScriptObject by hand in GWT?

Tags:

gwt

how could i create an JavaScriptObject by hand when i have this class

public class Person extends JavaScriptObject{
    protected Person(){}

    public final native String FirstName()/*-{
        return this.firstName;
    }-*/; 

    public final native String LastName()/*-{
        return this.lastName;
    }-*/;
 }

i am asking because i have an array of this JavaScriptObject Peron

public JsArray<Person> persons = JavaScriptObject.createArray().cast();

and i would like to full this array with some of these Person objects

Peson a = new Person();
a.setfirstName(textField1.getText());
a.setLastName(textField2.getText());
persons.push(a)

but i doesnt know how to create such an object by hand. The values of firstName and lastName i would take from an UI component like an textField. Please help!

like image 754
Pero Avatar asked Apr 28 '12 11:04

Pero


1 Answers

You should be able to do this?

Person a = (Person)JavaScriptObject.createObject().cast();
like image 185
krishnakumarp Avatar answered Sep 29 '22 10:09

krishnakumarp