2015-10-19 38 views
2

我想從客戶端javascript調用服務器端函數。我不敢肯定我在做什麼錯在這裏:AbstractJavaScriptComponent客戶端到服務器函數調用

public class Test extends AbstractJavaScriptComponent { 

public Test() { 
    addFunction("notifyServer", new JavaScriptFunction() { 

     @Override 
     public void call(JsonArray arguments) { 
      Notification.show("The client notified you!"); 

     } 
    }); 
} 

而且從JavaScript connector.js我這樣稱呼它

function test(){ 
    this.notifyServer(); 
    notifyServer(); 
} 

上述這些作品都沒有。每次我得到相同的堆棧跟蹤

Uncaught TypeError: this.notifyServer is not a function

回答

0

我解決了這個問題。我忘記this包裝只在連接包裝的範圍內可用。所以爲了打電話我必須這樣做的功能:

var serverObject; 

window.demo_test_Test = function() { 

    serverObject = this; 
} 

function test(){ 
    serverObject.notifyServer(); 
} 
相關問題