Hey,
currently I tried the 2. time to move our application from gwt 2.7 to gwt
2.8, but I have big problems with the changes of JsInterop.
The application contains a serverside java part, running in a jetty and the
client part, build with gwt, so I can reuse many software on server and
client side. (It is the main part of the website www.spreadshirt.com )
To use also the same data classes (containing only fields with getter and
setter, no other methods) on both sides, I used JsInterop and it works very
well with gwt 2.7 and exchanged the data as json.
Example Data class:
@JsType
public class MyObject {
private String id;
@JsProperty
public String getId() {
return id;
}
@JsProperty
public void setId(String id) {
this.id = id;
}
}
The class can be used on server side like any normal java class with any
REST Framework. On gwt side I was able to convert a transmitted json to the
class with:
MyObject myObject = getJsTypeObject(JsonUtils.safeEval(jsonString));
//use getter and setter to access fields
public static native <T> T getJsTypeObject(JavaScriptObject result)/*-{
return result;
}-*/;
And to create Objects on gwt side and send them to the server as json:
MyObject myObject = new MyObject();
myObject.setId("1");
String jsonString = stringify(myObject);
public static final native String stringify(Object result) /*-{
return JSON.stringify(result);
}-*/;
I also solved the problem of List and Map with an own Interface, which is
an ArrayList/HashMap on serverside and an own implemented native List/Map
on gwt side.
The application has more than 100 such Objects which are heavily used on
server and client side in many methods which are also be used on both
sides. So implementing them twice for server and client side would be a big
overhead.
Now is my question, how can I convert this gwt 2.7 code to gwt 2.8 (mainly
to be able to use Java8 syntax in future). I tried multiple variants, but
it seems for me, JsInterop in gwt 2.8 is not planned for such usecases
which were possible in gwt 2.7 withou any problems.
I can either use a native Javascript Object in gwt (native=true) or a in
GWT created Object in Javascript. But I see no solution to do both with the
same Type.
I get 2 Problems
- Casting issues: I can't use native=true because I also want to create
such Objects on gwt side, so on every assignment (jsonString to typed
variable) I get a cast exception and at least in superdev mode I can't
deactivate the cast exceptions
- field name problems: The jsonString of the last example is
{"id_g_$3":"1"} and not {"id":"1"} because the JsProperty for getter and
setter works only fine with native objects. If I add JsProperty to the
field itself, I can't do have JsProperty for the getter and setter, so I
have to add JsIgnore to them. But then when I work with native Objects I
can't use the getter and setter on gwt side. I would need JsProperty on
getter, setter and the field itself, but this is also not allowed.
Is there any solution for me? I love the idea to run the same code in a
normal java webapplication and to compile it gwt to run it on client side
(the gwt compiler produces very optimized js code and support code
splitting, remote logging with java stacktraces and debugging on live
website with superdev). I don't want to compile java code to js to run it
with nodejs on serverside.
Thanks a lot,
Jürgen
--
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 [email protected].
To post to this group, send email to [email protected].
Visit this group at https://groups.google.com/group/google-web-toolkit.
For more options, visit https://groups.google.com/d/optout.