[英]How to call GWT java function from Javascript?
是否可以從Javascript調用Java(GWT)方法? 從文檔中還不清楚。 此處的所有示例http://code.google.com/intl/ru/webtoolkit/doc/latest/DevGuideCodingBasicsJSNI.html演示了如何從JSNI(非JS)函數調用java函數。
更新1
這是一個Java代碼:
public class Test_GoogleWeb_JSNI_02 implements EntryPoint {
/**
* This is the entry point method.
*/
public void onModuleLoad() {
}
public static void Callee() {
Window.alert("Callee");
}
}
這是html中的調用者按鈕示例:
<input type='button' value='Call' onclick='Test02()'>
這里有一些我嘗試過但沒有用過的功能:
<script type="text/javascript">
function Test01() {
@com.inthemoon.tests.client.Test_GoogleWeb_JSNI_02::Callee()();
}
function Test02() {
com.inthemoon.tests.client.Test_GoogleWeb_JSNI_02::Callee()();
}
</script>
更新2
以下工作。
Java准備:
public void onModuleLoad() {
Prepare();
}
public static native void Prepare() /*-{
$doc.calleeRunner = @com.inthemoon.tests.client.Test_GoogleWeb_JSNI_02::Callee();
}-*/;
public static void Callee() {
Window.alert("Callee");
}
呼叫者:
function Test03() {
document.calleeRunner();
}
有沒有更好的辦法?
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.