GWT, GWT-Ext and MIME/Multipart Forms

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.

  1. Backup gwt-dev-windows.jar.
  2. Make directory com/google/gwt/dev/shell.
  3. Extract file com/google/gwt/dev/shell/JsValueGlue.java from gwt-dev-windows.jar into com/google/gwt/dev/shell.
  4. Delete files com/google/gwt/dev/shell/JsValueGlue.class and JsValueGlue.java from gwt-dev-windows.jar.
  5. 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”);
      }
    }

  6. Compile the class with gwt-dev-windows.jar in 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

  7. Finally, put the resulting class and the source file back into the JAR.

Comments 2

  1. Bill T wrote:

    Interesting… do you know if Ext GWT has the same issue?

    Posted 05 Aug 2008 at 9:14 pm
  2. Mihai wrote:

    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

  1. From Weekly GWT Links for 8/9/08 | GWT Site on 09 Aug 2008 at 11:43 am

    […] GWT, GWT-Ext and MIME/Multipart Forms A blog post discussing a workaround when using GWT-Ext file upload. […]

Post a Comment

Your email is never published nor shared. Required fields are marked *