exchange Class beetwen GWT widget and Vaadin application

Good morning.
I have a problem. In my application I defined a widget (GWT) to integrate a mapping component in Vaadin. Through
method updateFromUIDL exchange between the two components, some
variables (using method paintContent to the server). You can also exchange classes in addition to primitive types?
If not how can I exchange my classes between Vaadin application and GWT widget? An example?
I hope I was clear. Thanks

Good evening

You cannot directly send objects from the server to the client. You need to either use the addAttribute method or serialize the class somehow. One option is to do it manually like Vaadin does with e.g. MouseEventDetails, pass it as a String and deserialize it manually in the widget.

This is something we need to improve in a future version of the framework.

You can also use e.g. a JSON serializer and deserializer to make the work a bit easier for you. For instance if you use
Google Gson
on the server side and
GWTProJSONSerializer
on the client side you can make this pretty easy.

On the server side:


        target.addAttribute("data", new Gson().toJson(dataObject));

On the client side:


        dataObject = serializer.deSerialize(uidl.getStringAttribute("data"), MyDataObject.class.getName());

Note that the MyDataObject class needs to be in the “client” package so it is available to the client side/GWT code and it needs to implement JsonSerializable for GWTProJSONSerializer.

I have some doubts. The class that represents the object to be exchanged must implement
Paintable? Also what does it mean that the class must
reside on the client? I tried to follow your advice and using Gson
and Json but when I insert the part that deserializes does not compile
Widget. Thanks

The class does not need to implement Paintable.

“Residing on the client” here means that it needs to be in a “client” package under the package that has the widgetset .gwt.xml file - or in a subpackage of “client”. Otherwise, the GWT compiler will not find it. Probably also your widgetset compilation problem is caused by some classpath issues - note that the GWT compiler also needs the
sources
of all the code to be compiled to the client on its classpath.

If you are compiling the widgetset with the Eclipse plugin, you do not have full control over the GWT Compiler classpath - only classpath JARs that have GWT modules are used during the widgetset compilation. Therefore, you might need to use e.g. an ANT build script for building the widgetset instead of using the Eclipse plugin directly if you want to use non-Vaadin/GWT JARs in client side code.