> Hi Thomas,
>
> > Of course, if your really want Product as a "real" bean, and a List<?>
> > instead of a JsArray<?>, you can copy things around (see below); but
> > really I believe overlay types are much more readable than anything
> > using com.google.gwt.json.* classes.
>
> I used to use overlay type heavily (returning JSON from a Spring
> MVC/Jackson backend) and it worked quite well. Although I found it
> quite limiting to be unable to model "real" class hierarchies (JSOs
> must not be subclassed).
You can very well subclass JSOs (see how
com.google.gwt.dom.client.AnchorElement extends Element which in turn
extends Node).
What you cannot do is virtual dispatching (i.e. overring methods:
methods must be final, but not necessarily classes).
> I really do this a lot on the server side. I
> also really like to use the enhanced for loop for Lists
That's why I created JsCollections a while ago with a set of
JsArrays.toArray() methods that copies the JsArray into an array in
DevMode but just "casts" it in prod mode (i.e. no single overhead once
compiled to JS).
http://code.google.com/p/gwt-in-the-air/source/browse/trunk/src/net/ltgt/gwt/jscollections/client/JsArrays.java
> and just do a
> new Foo() instead of some tedious Foo.create().
That's really about "coding style", i.e. personal preference.
> Last but not least I
> don't have a "Generate getters/setters" in Eclipse for my JSOs :)
>
> All this led me to write a Generator which inspects my models ("real"
> beans) and emits JSON mapping code handling simple properties, object
> graphs and collections. That way I can work with real beans and
> collections of beans in my (business) code and do the mapping from/to
> JSON in my service/DAO layer (still sending/retrieving JSON to/from my
> backend).
Note that starting with GWT 2.0 JSOs can implement interfaces (as long
as no more than a single JSO class implements a given interface, so
there's no virtual dispatch) so you can "extract an interface" from
your server-side model and implement it as a JSO on the client side
(that would handily replace the "generate getters/setters" with
minimal effort); and there's work in progress to add a "lightweight
collections" module to GWT: compiles to much lighter weight JS code
than java.util.* collections and are still usable in a JVM (unlike
JsArray).
You'd use Jackson or similar on the server-side to (de)serialize to/
from JSON, and a simple JsonUtils.safeEval on the client side for the
parsing (and new JSONObject(jso).toString() for the serialization,
unless you wrap json2.js for a JSON.stringify emulation on browsers
that don't natively support it)
--
You received this message because you are subscribed to the Google Groups "Google Web Toolkit" group.
To post to this group, send email to google-web-toolkit@googlegroups.com.
To unsubscribe from this group, send email to google-web-toolkit+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/google-web-toolkit?hl=en.
No comments:
Post a Comment