Rectangle 27 0

Here is the correct working version based on logans answer. I added the instance variable which is needed because the myOnload() method is non-static. I also added the $entry() function to track error in GWT.

class MyClass{

   MyClass(){

     expose();

     // UiBinder stuff here
   }

   // Call this once. Exports your Java method as a javascript method
   public native void expose()/*-{
       var instance = this;
       $wnd.myOnLoadThing = $entry(function(){
           instance.@com.my.MyClass::myOnload()();
       });
    }-*/;

   public void myOnload(){
       // Put your java onload function here
   };
}

And in your uiBinder, make sure to call that myOnLoadThing

<g:HTMLPanel>
<div class="fb-login-button" data-max-rows="1" data-size="xlarge" 
            data-show-faces="false" data-auto-logout-link="false" 
            data-scope="email,publish_actions,user_birthday,user_likes" 
            onlogin="window.myOnLoadThing();"></div>

</g:HTMLPanel>

java - How to use JavaScript callback function in GWT UiBinder? - Stac...

java javascript html gwt jsni
Rectangle 27 0

You can't put a <script> in UiBinder and expect to see it loaded and executed for the same reasons you cannot put a <script> in a innerHTML in JS with the same expactations (simply because HTMLPanel and UiBinder will use innerHTML under-the-hood).

If you need to load scripts dynamically, have a look at the ScriptInjector:

ScriptInjector.fromUrl(GWT.getModuleBaseURL() + 'jquery.js').inject();

I suppose GQuery uses ScriptInjector or works similarly.

java - How to use JavaScript with gwt Uibinder - Stack Overflow

java javascript gwt uibinder
Rectangle 27 0

<script src="jquery.js"></script>
<script src="jquery.roundabout.js"></script>

in the project.html and then executing the relevant JavaScript with JSNI call when the relevant page loaded (my presenter).

java - How to use JavaScript with gwt Uibinder - Stack Overflow

java javascript gwt uibinder
Rectangle 27 0

In your class, you can expose a native javascript method, for example called myOnLoadThing

class MyClass{

   MyClass(){

     expose();

     // UiBinder stuff here
   }

   // Call this once. Exports your Java method as a javascript method
   public native void expose()/*-{
       $wnd.myOnLoadThing = function(){
            @com.my.MyClass::myOnload()();
       }
    }-*/;

   public void myOnload(){
       // Put your java onload function here
   };
}

And in your uiBinder, make sure to call that myOnLoadThing

<g:HTMLPanel>
<div class="fb-login-button" data-max-rows="1" data-size="xlarge" 
            data-show-faces="false" data-auto-logout-link="false" 
            data-scope="email,publish_actions,user_birthday,user_likes" 
            onlogin="window.myOnLoadThing();"></div>

</g:HTMLPanel>

I think you missed the var instance = this;

@confile You should not make edits that change the meaning of the answer. Instead, you should point out your change/suggestion here in comments, and allow the original poster to change if they agree. If you feel the change is significant enough, perhaps you can also creat your own answer to the question.

thanks for pointing that out @Gaffi -- I was wondering what happened to this thread

java - How to use JavaScript callback function in GWT UiBinder? - Stac...

java javascript html gwt jsni