Announcement

Collapse
No announcement yet.
X
  • Filter
  • Time
Clear All
new posts

    Using SmartGWT with JSNI

    In my project, I need to use some code written in an external JS. It looks like JSNI seems to be the solution to use. I am creating a test prototype right now to ensure both sides are working properly.
    When I run and compile, I see the console logs in the browser from the events being called. However, the java methods are not being called.
    After trying many scenarios, I also noticed that if I remove the $entry wrapper from the exportStaticMethods(), the opposite occurs. I see the System.out being called in my java code, however the console logs from the JavaScript in the browser are not being called.
    I am trying to figure what is causing the behavior and if there is a small missing piece I overlooked or if there is anything SmartGWT specific maybe I need to do.
    I have already reviewed the GWT JSNI documentation for calling a Java method from js.

    GWT and Java side
    I have gone into the onModuleLoad() method of my EntryPoint class and added a static method called exportStaticMethods(). I also created the PokePingClass.java file listed below.
    EntryPointClass.java

    public class EntryPointClass implements EntryPoint
    {
    @Override public void onModuleLoad()
    {
    exportStaticMethods();
    // load application here.
    }

    public static native void exportStaticMethods() /*-{
    $wnd.pingApp = $entry((function)
    { @com.application.PokePingClass::pingApp()(); });
    }-*/ }

    PokePingClass.java

    public class PokePingClass
    {
    public static void pingApp()
    {
    System.out.println("pingApp() called");
    }
    }

    HTML and js
    In the .html file of the project, I added a hidden div element of id 'ping', as well as the ping.js file.

    <html>
    <head>
    .
    . <!-- other stuff -->
    .
    <script type='text/javascript' src='pokeping.js</script>
    </head>

    <body>
    .
    . <!-- other stuff -->
    . <div id="ping" style="visibility: hidden;"></div>
    </body>
    </html>

    ping.js

    $(document).ready(function)
    {
    var $pp = $('#ping');
    var pingApp = function()
    {
    console.log("app handling ping event");
    window.parent.pingApp();
    };

    $pp.trigger('pingApp');
    }
    Last edited by siegersallee; 6 Jan 2017, 06:01.

    #2
    It looks like your JavaScript code is relying on JQuery. Does the problem you're reporting happen without JQuery?

    Comment


      #3
      That is correct.

      I have jquery loaded in the .html file as well. It is not running in no conflicts mode. Using version, jquery-2.2.4.min.js

      Comment


        #4
        We're going to need a minimal case without JQuery. You may want to search the web to see whether other people are having issues using JQuery with GWT.

        Comment

        Working...
        X