GWT and GXT Usage Experience Summary

Source: Internet
Author: User
Tags serialization
Reprint Midnight Coffee
Jolestar ' s blog, the Shepherd's Bachelor blog

One of the company's projects, finally decided to use GWT to do the backend interface, so began to study GWT. The previous understanding of GWT was just a helloworld look at the effect.

A. Spring's integration

It was a problem at first. How to give the server side of the Goolge RPC Service to spring management. Find a ready-made open source project to do this thing-gwt-widget (http://gwt-widget.sourceforge.net/) subproject GWT-SL (GWT Server Library). GWT's server side is actually a servlet, but it must inherit from Remoteserviceservlet. Remoteserviceservlet is responsible for the resolution of the GWT remote call request and the serialization of the results of the output. GWT-SL provides a gwtspringcontroller that inherits from Remoteserviceservlet and implements the Controller interface of spring. So just have your GWT RPC service inherit from Gwtspringcontroller, and when the normal spring controller configuration is OK. If you don't like the way you inherit, GWT-SL also provides a solution for spring's proxy mode. Refer to the documentation (HTTP://GWT-WIDGET.SOURCEFORGE.NET/?Q=NODE/51) in detail.

Two. Selection of interface controls

GWT defaults to providing too few controls to meet your needs. Fortunately, there are third-party controls to choose from.
1.gwt-ext (http://code.google.com/p/gwt-ext/) (http://gwt-ext.com/)
2.Ext GWT (GXT) (http://www.extjs.com/products/gxt/)

These two projects are to integrate the control of ext into GWT, the name of the project is similar, and began to confuse me. GXT is ext official out, but see Gwt-ext demo, Silk no less inferior to GXT. However, due to copyright issues, Gwt-ext has not been updated. It is best not to mix two control libraries, because there are differences between the theme mode of each control library, the event model, the MVC architecture, and the JavaBean serialization.

Three. Manage your GWT project with Maven
Java project, no maven how to line. Found two GWT's maven plug-ins.
1.http://code.google.com/p/gwt-maven/
2.http://mojo.codehaus.org/gwt-maven-plugin/

We are choosing the latter. After the GWT project is established, the default Web directory is in the/war directory, and the Maven Maven-war-plugin (/src/main/webapp directory) conflicts, so you need to modify the Maven-war-plugin configuration.

1 2 3 4 5 6 7 8 < plugin > < groupId >org.apache.maven.plugins</groupId > < Artifactid >maven-war-plugin</ar Tifactid > < version >2.0.2</version > < configuration > < warsourcedirectory >war</Warsou Rcedirectory > </configuration > </plugin >

Four. Things to note about GWT client and server-side interactions and frequently asked questions

1. Both client and server-side interactive parameters (RPC service) must implement either the Java.io.Serializable interface or the Com.google.gwt.user.client.rpc.IsSerializable interface.

GWT does not use the Java serialization mechanism, only uses the serializable interface as a flag, but also facilitates compatibility. But GWT's serialization mechanism can cause a lot of weird problems.

1 Type ' XXX ' is not serializable and has no concrete serializable subtypes

This exception is typically due to the fact that the class is not serialized or that one of its properties is not serialized.

2.Class cannot be passed in the remote invocation method because GWT's class is a finite function class.

3.

1 Type ' Org.hibernate.collection.PersistentSet ' is not included in the set of types which can is serialized by this Seriali Zationpolicy or its Class object could is loaded.

This error occurs if the Hibernate's ORM mapping object is serialized directly into GWT, and the collection map is used.

4.

1 <span>a Legacy, 1.3.3 compatible, serialization policy would be used. Experience Serializationexceptions as a result. </span>

This error is sometimes caused by the client not refreshing.

5.

1 Type XXX is not included in the set of types which can is serialized by this Serializationpolicy or its Class object Coul D is loaded. For the security purposes, this type is not is serialized.

The reason for this error is that the serialized object is not in the whitelist. Whitelist is a GWT compiler that scans Java source code when compiling Java classes, and only Java classes in whitelist can be serialized in GWT. The most common type of error is declaring a Java collection class, but not using the Java generics to set the types that might appear in the collection class, so that the GWT compiler cannot add the types that might appear to the whitelist. When running, GWT encounters a type that is not on the whitelist and doesn't know how to serialize it.
Similarly, GWT does not allow you to declare the properties of a class using object. Because GWT's compiler adds all types that need to be serialized and the subtypes of that type to the whitelist at compile time. If object is allowed to appear, all types appear in the whitelist. So for efficiency, GWT is best not to use types with higher class hierarchies.

This error can refer to: http://stackoverflow.com/questions/138099/how-do-i-add-a-type-to-gwts-serialization-policy-whitelist

6. Customizing serialization

GWT's serialization rules are so numerous that you need to customize the way serialization is necessary.
For example, to customize the serialization of the Game class, create a new Game_customfieldserializer class in the package directory of Game:

1 2 3 4, 5 6 7 8 9 10 11 12 13 14 15 public class Game_customfieldserializer {public static void deserialize (Serializationstreamreader StreamReader, Game Instance) throws SerializationException {} public static Game instantiate (Serializationstreamreader R) throws ionexception {Game Game = new Game (); Game.setname (r.readstring ()); return Game.} public static void Serialize (Serializa Tionstreamwriter StreamWriter, Game g) throws SerializationException {streamwriter.writestring (G.getname ());}

Generally only need to implement instantiate and serialize two methods. Write properties must be guaranteed in the same order as read properties.

Five. Other GWT RELATED LINKS

1.GWT related Project Http://www.infoq.com/cn/news/2010/04/GWT-Roundup

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.