Created
February 22, 2019 18:17
-
-
Save branflake2267/6c26ad44f4f7ec37a9bc2f7e7eb4c8df to your computer and use it in GitHub Desktop.
GXT 4.x JSNI example. Start the app later, by importing the script. Call into the application from Javascript.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| package com.sencha.gxt.test.client.jsni_callinto; | |
| import com.google.gwt.core.client.EntryPoint; | |
| import com.sencha.gxt.widget.core.client.info.Info; | |
| public class JsniExample implements EntryPoint { | |
| private native void myInfo() /*-{ | |
| function myInfo(value) { | |
| // Call static java method | |
| // TODO: change the package path based on where you put this file... | |
| $entry(@com.sencha.gxt.test.client.jsni_callinto.JsniExample::myJavaInfo(Ljava/lang/String;)(value)); | |
| } | |
| // Add the method to the window, so it can be called from anywhere | |
| // Goto web browser console and call > this.myInfo('Test'); | |
| $wnd.myInfo = myInfo; | |
| }-*/; | |
| // called onload | |
| @Override | |
| public void onModuleLoad() { | |
| // add function to window object | |
| myInfo(); | |
| } | |
| public static void myJavaInfo(String value) { | |
| Info.display("Works", "From Javascript: " + value); | |
| } | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <!doctype html> | |
| <html> | |
| <head> | |
| <meta http-equiv="content-type" content="text/html; charset=UTF-8"> | |
| <meta name="viewport" | |
| content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no"> | |
| <title>GXT Project 4.0</title> | |
| <!-- The project.gwt.xml entrypoint --> | |
| <!-- <script type="text/javascript" src="MyGxtProject40/MyGxtProject40.nocache.js"></script> --> | |
| </head> | |
| <body> | |
| <script> | |
| startApp = () => { | |
| // Instead import the javascript entrypoint at anytime. | |
| let st = document.createElement("script"); | |
| st.type = "text/javascript"; | |
| st.src = "./MyGxtProject40/MyGxtProject40.nocache.js"; | |
| document.getElementsByTagName('head')[0].appendChild(st) | |
| } | |
| </script> | |
| <!-- Manually import the GWT entrypoint in the future --> | |
| <!-- This will call onLoad --> | |
| <input type='button' value='Start app' onclick="startApp();"></input> | |
| <br/> | |
| <br/> | |
| <input type='button' value='Test info' onclick="window.myInfo('Hello')"></input> | |
| </body> | |
| </html> |
Author
branflake2267
commented
Feb 22, 2019

Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment