Showing posts with label gwt. Show all posts
Showing posts with label gwt. Show all posts

Wednesday, June 12, 2013

While using dev mode of GWT in Jetbrains IDEA, which runs jetty, I need to use spring instrumentation.
Default parameter -javaagent:spring-instrumentation.jar didn't work for me.
To run it wit Jetty you are to add additional parameter -Xbootclasspath. The final string:
-javaagent:/spring-instrument-3.2.0.RELEASE.jar -Xbootclasspath/a:spring-instrument-3.2.0.RELEASE.jar


Thanks to this:
http://gradle.1045684.n5.nabble.com/Java-Agent-LTW-problem-with-Gradle-and-Jetty-td4938600.html

Thursday, May 30, 2013

Using nested arrays of complex types in GWT

Java's code:

public class Person {
   private String name;
   private int[] luckyDays;

   public String getName() {
      return name;
   }

   public void setName(String name) {
      this.name = name;
   }

   public int[] getLuckyDays() {
      return luckyDays;
   }

   public void setLuckyDays(int[] luckyDays) {
      this.luckyDays = luckyDays;
   }

}


public class Family {
   private Person[] persons;

   public Person[] getPersons() {
      return persons;
   }

   public void setPersons(Person[] persons) {
      this.persons = persons;
   }

}

in GWT will be (only getters for deserializer):


import com.google.gwt.core.client.JavaScriptObject;
import com.google.gwt.core.client.JsArray;

public class PersonClient extends JavaScriptObject {

   protected PersonClient() {}

   
   public final native String getName() /*-{
      return this.name;

   }-*/;

   public final native JsArrayNumber
getLuckyDays() /*-{
      return this.
luckyDays;
   }-*/;


}

import com.google.gwt.core.client.JavaScriptObject;
import com.google.gwt.core.client.JsArray;

public class FamilyClient extends JavaScriptObject {


   protected FamilyClient() {} 


   public final native JsArray<PersonClient> getPersons() /*-{
      return this.
persons
   }-*/;


}

Example how to use it:


JsArrayString names = Properties.createArray().cast();
s.push("Foo");

Properties properties = Properties.create();
properties.setNumber("from", from.getValue().getTime());
properties.setNumber("to", to.getValue().getTime());
properties.set("names", s);


GQuery.getJSON("/getPersonsByNames.json", $$(params), new Function() {

   @Override
   public void f() {



      JavaScriptObject response = (JavaScriptObject) this.getDataObject();
     
FamilyClient family = response.cast();

      for (int i = 0; i <
family.getPersons().length(); i++) {
         
PersonClient person = family.getPersons().get(i);
         ...
      }
   }
}