Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/gwt/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/sql-server-2008/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
查找GWT模块何时加载_Gwt_Jsni - Fatal编程技术网

查找GWT模块何时加载

查找GWT模块何时加载,gwt,jsni,Gwt,Jsni,我正在以以下方式将GWT方法导出到本机javascript: public class FaceBookGalleryEntryPoint implements EntryPoint { @Override public void onModuleLoad() { FacebookGallery facebookGallery = new FacebookGallery(); RootPanel.get().add(facebookGaller

我正在以以下方式将GWT方法导出到本机javascript:

public class FaceBookGalleryEntryPoint implements EntryPoint {

    @Override
    public void onModuleLoad() {

        FacebookGallery facebookGallery = new FacebookGallery();
        RootPanel.get().add(facebookGallery);

        initLoadGallery(facebookGallery);
    }

    private native void initLoadGallery(FacebookGallery pl) /*-{
        $wnd.loadGallery = function (galleryId) {
            pl.@com.example.fbg.client.FacebookGallery::loadGallery(Ljava/lang/String;)(galleryId);
        };
    }-*/;
}
在主机页中,我尝试调用它:

<html>
    <head>
        <title>Facebook image gallery</title>
        <script type="text/javascript"
            src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js"></script>     
    </head>

    <body>
        <script type="text/javascript" src="/fbg/fbg.nocache.js"></script>
        <h1>Facebook gallery test</h1>
        <script type="text/javascript">
            $(document).ready(function() {
                loadGallery('blargh');              
            });
        </script>
    </body>
</html>

Facebook图片库
Facebook多媒体资料测试
$(文档).ready(函数(){
装载库(“废话”);
});
不幸的是,调用document.ready回调时,函数尚未定义。当从Firebug控制台手动执行时,该功能工作正常

我可以每50毫秒进行一次轮询,直到找到一个使用该名称定义的函数,但这似乎是一种可怕的方法


如何在加载模块以及函数可用时得到通知?

我会尝试在hostpage中定义一个回调函数,并在onModuleLoad()方法末尾从GWT调用它

主机页功能:

<script type="text/javascript">
  function onGwtReady() {
    loadGallery('blargh');              
  };
</script>

谢谢,看起来很有趣-尤其是延迟命令位。今晚我将对此进行一次尝试。顺便说一句,在GWT2.1中,您应该使用Scheduler().get().scheduleDeferred(),谢谢您的Scheduler提示。
public void onModuleLoad() {
  FacebookGallery facebookGallery = new FacebookGallery();
  RootPanel.get().add(facebookGallery);

  initLoadGallery(facebookGallery);

  // Using a deferred command ensures that notifyHostpage() is called after
  // GWT initialisation is finished.
  Scheduler.get().scheduleDeferred(new Command() {
    public void execute() {
      notifyHostpage();
    }
  }
}

private native void notifyHostpage() /*-{
  $wnd.onGwtReady();
}-*/;