As I was working on a Google Web Toolkit and Google App Engine application that I’m doing as a means to get better at GAE and some more advanced GWT concepts (UiBinder, MVP design pattern, RPC, etc.) - at least advanced for me right now, I decided to log every new thing I learn, so that, 1) I will be able to remember them tomorrow, and 2) other can hopefully learn, since there seems to be very little [quality] documentation about GWT and GAE for beginners.
Learn Google Web Toolkit Day #1
Today, or, day #1, as I decided to call this first blog entry on this subject, I learned two things, which I’ll call “tips” from now on, though I know they’re not so much tips as they’re like, bits of wisdom:
GWT Tip #1 - You can’t use Google App Engine objects in your client GWT code through RPCs
GWT Tip #2 - If your data models have complex constructors (a constructor that takes arguments), you must also provide a no argument constructor if you’re sending the model to the client through an RPC
I’m not sure exactly why this is yet, but some of my models, as simple as they were, didn’t have a no argument constructor, thus breaking my RPC calls. I just added a blank constructor, and life is good.
Update: After making this same mistake again today, I’ve realized that the no argument constructor is needed in the serialization process of your model. So if you get such error message as:
com.google.gwt.user.client.rpc.SerializationException: Type <your.model.class> was not included in the set of types which can be serialized by this SerializationPolicy or its Class object could not be loaded. For security purposes, this type will not be serialized.
So if you get this error during an RPC, be sure to include that empty constructor, and you’ll fix the problem. Of course, that goes without saying that you should include the path to your model in the GWT module descriptor, as in:
<source path="shared" />
And that the model class itself implements
GWT Tip #3 - How to setup GWT RPC Servlet url-pattern
One thing I’ve been confused about with GWT RPC is the annotation
@RemoteServiceRelativePath. The actual path that this specifies is the servlet path (its url mapping) to the servlet that will satisfy the remote procedure call.
Whatever value you specify in the annotation, let’s say,
will be used in the web.xml
The first part of that URL pattern is the name of your GWT module. If you don’t rename your module in the module.gwt.xml file, then the first part of the URL would be com.package.name.client. If you do rename your module, as in
Then that renamed attribute would be used in the web.xml file instead.