When trying to create a simple GWT-Ext file upload (GWT-Ext 2.0.4, Ext-JS 2.0.2, GWT 1.5 Windows), GWT reports the following hosted mode error upon form submit:
com.google.gwt.dev.shell.HostedModeException: Expected primitive type int; actual value was undefined
According to some reports, older versions of GWT display a slightly different error message.
com.google.gwt.dev.shell.HostedModeException: Calling method 'onActionComplete': JavaScript undefined, expected int
This error occurs because of a bug in GWT-Ext whereby the library cannot locate the HTTP response code and uses “undefined” instead. GWT-Ext needs the response code to call methods on your form listener with the right arguments. GWT-Ext goes deep inside GWT code, where a cast to an int fails miserably because of this undefined value. The error goes away in browser mode because the cast is never performed (and incidentally because you typically don’t use the response code in the form listener).
Until GWT-Ext fixes the problem, I have to keep working in hosted mode, or else, my development process will become painfully slow. My solution: PATCH GWT itself so it doesn’t throw an error when casting an undefined value to an int!.
Here are the steps. Execute them in your local GWT installation. Needless to say, these same steps should work for a Linux or a Mac installation of Google Web Toolkit.
- Backup
gwt-dev-windows.jar. - Make directory
com/google/gwt/dev/shell. - Extract file
com/google/gwt/dev/shell/JsValueGlue.javafromgwt-dev-windows.jarintocom/google/gwt/dev/shell. - Delete files
com/google/gwt/dev/shell/JsValueGlue.classandJsValueGlue.javafromgwt-dev-windows.jar. - In the extracted
JsValueGlue.java, locate the offending line (my stack trace tells me it’s line 51), and add the code in bold:
if (type.isPrimitive()) { if (value.isUndefined()) { if (type == Integer.TYPE) { return (T) Integer.valueOf(-1); } throw new HostedModeException("Expected primitive type " + type + "; actual value was undefined"); } else if (value.isNull()) { throw new HostedModeException("Expected primitive type " + type + "; actual value was null"); } } - Compile the class with
gwt-dev-windows.jarin the classpath. Use Java 1.5, as this is the version that the existing classes were compiled as.
javac -classpath gwt-dev-windows.jar com/google/gwt/dev/shell/JsValueGlue.java
- Finally, put the resulting class and the source file back into the JAR.
Comments 2
Interesting… do you know if Ext GWT has the same issue?
Posted 05 Aug 2008 at 9:14 pm ¶I’m not sure what you mean, Bill. This is a GWT-Ext issue. The reason why I attacked this issue in GWT, and not GWT-Ext, is that I have the GWT source code and a good stack trace.
Posted 06 Aug 2008 at 11:52 am ¶Trackbacks & Pingbacks 1
[...] GWT, GWT-Ext and MIME/Multipart Forms A blog post discussing a workaround when using GWT-Ext file upload. [...]
Post a Comment
You must be logged in to post a comment.