ArcBees / gwtquery

A jQuery clone for GWT, and much more.
MIT License
85 stars 38 forks source link

Version 1.4.0 doesn't seem to work with IE9 #269

Closed BenDol closed 10 years ago

BenDol commented 10 years ago

What steps will reproduce the problem?

  1. Create a maven gwt project that includes a dependency on gwtquery 1.4.0
  2. Run the project (either dev or prod).
  3. See exceptions thrown when gwtquery code is executed.

What is the expected output? What do you see instead?

I expect things to work as documented. But instead get exceptions.

What version of the product are you using? On what operating system?

1.4.0 on IE 9, Windows 7.

Please provide any additional information below.

[ERROR] [gwtquerytest] - Failed to create an instance of 'com.google.gwt.query.client.Console' via deferred binding

15:29:58.136 [ERROR] [gwtquerytest] Failed to create an instance of 'com.google.gwt.query.client.Console' via deferred binding

com.google.gwt.core.client.JavaScriptException: (TypeError) @com.google.gwt.query.client.impl.ConsoleBrowser$ConsoleIe9::init()([]): Unable to get value of the property 'log': object is null or undefined at com.google.gwt.dev.shell.BrowserChannelServer.invokeJavascript(BrowserChannelServer.java:249) at com.google.gwt.dev.shell.ModuleSpaceOOPHM.doInvoke(ModuleSpaceOOPHM.java:136) at com.google.gwt.dev.shell.ModuleSpace.invokeNative(ModuleSpace.java:571) at com.google.gwt.dev.shell.ModuleSpace.invokeNativeVoid(ModuleSpace.java:299) at com.google.gwt.dev.shell.JavaScriptHost.invokeNativeVoid(JavaScriptHost.java:107) at com.google.gwt.query.client.impl.ConsoleBrowser$ConsoleIe9.init(ConsoleBrowser.java) at com.google.gwt.query.client.impl.ConsoleBrowser$ConsoleIe9.<init>(ConsoleBrowser.java:43) at com.google.gwt.query.client.impl.ConsoleBrowser.<init>(ConsoleBrowser.java:131) at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method) at sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source) at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source) at java.lang.reflect.Constructor.newInstance(Unknown Source) at com.google.gwt.dev.shell.ModuleSpace.rebindAndCreate(ModuleSpace.java:475) at com.google.gwt.dev.shell.GWTBridgeImpl.create(GWTBridgeImpl.java:49) at com.google.gwt.core.shared.GWT.create(GWT.java:57) at com.google.gwt.core.client.GWT.create(GWT.java:85) at com.google.gwt.query.client.GQuery.<clinit>(GQuery.java:136) at com.gwtquerytest.client.EntryPt.onModuleLoad(EntryPt.java:21) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source) at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) at java.lang.reflect.Method.invoke(Unknown Source) at com.google.gwt.dev.shell.ModuleSpace.onLoad(ModuleSpace.java:406) at com.google.gwt.dev.shell.OophmSessionHandler.loadModule(OophmSessionHandler.java:200) at com.google.gwt.dev.shell.BrowserChannelServer.processConnection(BrowserChannelServer.java:526) at com.google.gwt.dev.shell.BrowserChannelServer.run(BrowserChannelServer.java:364) at java.lang.Thread.run(Unknown Source)

[ERROR] [gwtquerytest] - Unable to load module entry point class com.gwtquerytest.client.EntryPt (see associated exception for details)

15:29:58.204 [ERROR] [gwtquerytest] Unable to load module entry point class com.gwtquerytest.client.EntryPt (see associated exception for details)

java.lang.RuntimeException: Deferred binding failed for 'com.google.gwt.query.client.Console' (did you forget to inherit a required module?) at com.google.gwt.dev.shell.GWTBridgeImpl.create(GWTBridgeImpl.java:53) at com.google.gwt.core.shared.GWT.create(GWT.java:57) at com.google.gwt.core.client.GWT.create(GWT.java:85) at com.google.gwt.query.client.GQuery.<clinit>(GQuery.java:136) at com.gwtquerytest.client.EntryPt.onModuleLoad(EntryPt.java:21) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source) at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) at java.lang.reflect.Method.invoke(Unknown Source) at com.google.gwt.dev.shell.ModuleSpace.onLoad(ModuleSpace.java:406) at com.google.gwt.dev.shell.OophmSessionHandler.loadModule(OophmSessionHandler.java:200) at com.google.gwt.dev.shell.BrowserChannelServer.processConnection(BrowserChannelServer.java:526) at com.google.gwt.dev.shell.BrowserChannelServer.run(BrowserChannelServer.java:364) at java.lang.Thread.run(Unknown Source) Caused by: com.google.gwt.core.ext.UnableToCompleteException: (see previous log entries) at com.google.gwt.dev.shell.ModuleSpace.rebindAndCreate(ModuleSpace.java:513) at com.google.gwt.dev.shell.GWTBridgeImpl.create(GWTBridgeImpl.java:49) at com.google.gwt.core.shared.GWT.create(GWT.java:57) at com.google.gwt.core.client.GWT.create(GWT.java:85) at com.google.gwt.query.client.GQuery.<clinit>(GQuery.java:136) at com.gwtquerytest.client.EntryPt.onModuleLoad(EntryPt.java:21) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source) at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) at java.lang.reflect.Method.invoke(Unknown Source) at com.google.gwt.dev.shell.ModuleSpace.onLoad(ModuleSpace.java:406) at com.google.gwt.dev.shell.OophmSessionHandler.loadModule(OophmSessionHandler.java:200) at com.google.gwt.dev.shell.BrowserChannelServer.processConnection(BrowserChannelServer.java:526) at com.google.gwt.dev.shell.BrowserChannelServer.run(BrowserChannelServer.java:364) at java.lang.Thread.run(Unknown Source)

[ERROR] [gwtquerytest] - Failed to load module 'gwtquerytest' from user agent 'Mozilla/5.0 (compatible; MSIE 9.0; Windows NT 6.1; WOW64; Trident/5.0; SLCC2; .NET CLR 2.0.50727; .NET CLR 3.5.30729; .NET CLR 3.0.30729; Media Center PC 6.0; InfoPath.2; .NET4.0C; .NET4.0E)' at 127.0.0.1:62851

15:29:58.249 [ERROR] [gwtquerytest] Failed to load module 'gwtquerytest' from user agent 'Mozilla/5.0 (compatible; MSIE 9.0; Windows NT 6.1; WOW64; Trident/5.0; SLCC2; .NET CLR 2.0.50727; .NET CLR 3.5.30729; .NET CLR 3.0.30729; Media Center PC 6.0; InfoPath.2; .NET4.0C; .NET4.0E)' at 127.0.0.1:62851

public class EntryPt implements EntryPoint
{
    @SuppressWarnings("nls")
    @Override
    public void onModuleLoad()
    {
        RootPanel.get().add(new Label("Hello World"));

        $("div", RootPanel.get()).on("click", new Function()
        {
            @Override
            public boolean f(Event e)
            {
                EventTarget et = e.getEventTarget();
                Element elem = et.cast();
                System.out.println(elem);
                return false;
            }
        });
    }
}

Source: http://code.google.com/p/gwtquery/issues/detail?can=2&start=0&num=100&q=&colspec=ID%20Type%20Status%20Priority%20Milestone%20Owner%20Summary&groupby=&sort=&id=188

Hoping this will be resolved soon.

manolo commented 10 years ago

duplicated of issue #260 , update your project to 1.4.1-SNAPSHOT

jDramaix commented 10 years ago

We should maybe think to release 1.4.1 version

BenDol commented 10 years ago

For anyone that wants a temporary workaround in 1.4.0:

/*
 * Copyright 2013, The gwtquery team.
 *
 * Licensed under the Apache License, Version 2.0 (the "License"); you may not
 * use this file except in compliance with the License. You may obtain a copy of
 * the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
 * License for the specific language governing permissions and limitations under
 * the License.
 */
package com.google.gwt.query.client.impl;

import com.google.gwt.core.client.JavaScriptObject;
import com.google.gwt.query.client.Console;
import com.google.gwt.query.client.GQuery;

/**
 * Implementation of the Console interface based on the
 * browser console.
 */
public class ConsoleBrowser implements Console {

  /**
   * http://whattheheadsaid.com/2011/04/internet-explorer-9s-problematic-console-object
   */
  private static class ConsoleIe8 extends ConsoleIe9 {
    @Override
    protected native boolean init()/*-{
      try {
        Function.prototype.call.call($wnd.console.log, $wnd.console, Array.prototype.slice.call(arguments));
        return true;
      }
      catch(e) {
        return false;
      }
    }-*/;
  }

  /**
   * See: http://whattheheadsaid.com/2011/04/internet-explorer-9s-problematic-console-object
   */
  private static class ConsoleIe9 extends ConsoleImpl {

    private boolean initialized = false;

    public ConsoleIe9(){
        initialized = init();
    }

    protected native boolean init()/*-{
      try {
        [ "log", "info", "warn", "error", "dir", "clear", "profile", "profileEnd" ]
          .forEach(function(method) {
              $wnd.console[method] = this.call($wnd.console[method], $wnd.console);
          }, Function.prototype.bind);

        return true;
      }
      catch(e) {
        return false;
      }
    }-*/;

    @Override
    public void clear() {
      if (initialized) super.clear();
    }
    @Override
    public void dir(Object arg) {
      if (initialized) super.dir(arg);
    }
    @Override
    public void error(Object arg) {
      if (initialized) super.error(arg);
    }
    @Override
    public void info(Object arg) {
      if (initialized) super.info(arg);
    }
    @Override
    public void profile(String title) {
      if (initialized) super.profile(title);
    }
    @Override
    public void profileEnd(String title) {
      if (initialized) super.profileEnd(title);
    }
    @Override
    public void warn(Object arg) {
      if (initialized) super.warn(arg);
    }
    @Override
    public void group(Object arg) {}
    @Override
    public void groupCollapsed(Object arg) {}
    @Override
    public void groupEnd() {}
    @Override
    public void time(String title) {}
    @Override
    public void timeStamp(Object arg) {}
    @Override
    public void timeEnd(String title) {}
  }

  /**
   * Default implementation: webkit, opera, FF, ie10
   */
  private static class ConsoleImpl {
    public native void clear() /*-{
      $wnd.console.clear();
    }-*/;

    public native void dir(Object arg) /*-{
      $wnd.console.dir(arg);
    }-*/;

    public native void error(Object arg) /*-{
      $wnd.console.error(arg);
    }-*/;

    public native void group(Object arg) /*-{
      $wnd.console.group(arg);
    }-*/;

    public native void groupCollapsed(Object arg) /*-{
      $wnd.console.groupCollapsed(arg);
    }-*/;

    public native void groupEnd() /*-{
      $wnd.console.groupEnd();
    }-*/;

    public native void info(Object arg) /*-{
      $wnd.console.info(arg);
    }-*/;

    public native void log(Object arg) /*-{
      $wnd.console.log(arg);
    }-*/;

    public native void profile(String title) /*-{
      $wnd.console.profile(title);
    }-*/;

    public native void profileEnd(String title) /*-{
      $wnd.console.profileEnd(title);
    }-*/;

    public native void time(String title) /*-{
      $wnd.console.time(title);
    }-*/;

    public native void timeEnd(String title) /*-{
      $wnd.console.timeEnd(title);
    }-*/;

    public native void timeStamp(Object arg) /*-{
      $wnd.console.timeStamp(arg);
    }-*/;

    public native void warn(Object arg) /*-{
      $wnd.console.warn(arg);
    }-*/;
  }

  private ConsoleImpl impl;

  public ConsoleBrowser() {
    impl = GQuery.browser.ie8? new ConsoleIe8(): GQuery.browser.ie9? new ConsoleIe9(): new  ConsoleImpl();
  }

  @Override
  public void clear() {
    impl.clear();
  }

  @Override
  public void dir(Object arg) {
    impl.dir(toJs(arg));
  }

  @Override
  public void error(Object arg) {
    impl.error(toJs(arg));
  }

  @Override
  public void group(Object arg) {
    impl.group(toJs(arg));
  }

  @Override
  public void groupCollapsed(Object arg) {
    impl.groupCollapsed(toJs(arg));
  }

  @Override
  public void groupEnd() {
    impl.groupEnd();
  }

  @Override
  public void info(Object arg) {
    impl.info(toJs(arg));
  }

  @Override
  public void log(Object arg) {
    impl.log(toJs(arg));
  }

  @Override
  public void profile(String title) {
    impl.profile(title);
  }

  @Override
  public void profileEnd(String title) {
    impl.profileEnd(title);
  }

  @Override
  public void time(String title) {
    impl.time(title);
  }

  @Override
  public void timeEnd(String title) {
    impl.timeEnd(title);
  }

  @Override
  public void timeStamp(Object arg) {
    impl.timeStamp(toJs(arg));
  }

  @Override
  public void warn(Object arg) {
    impl.warn(toJs(arg));
  }

  /**
   * Don't pass GWT Objects to JS methods
   */
  private Object toJs(Object arg) {
    if (arg instanceof JavaScriptObject || arg instanceof String) {
      return arg;
    } else {
      return String.valueOf(arg);
    }
  }
}

Probably lots of other issues that will be resolved in 1.4.1, but I am using GwtQuery for a commercial product and important to have IE9 compatibility until then.

cplaetzinger commented 10 years ago

@BenDol thanks for posting this workaround. Works great!