Vaadin : how to get return value from javascript methods?

你说的曾经没有我的故事 提交于 2019-12-08 19:40:30

no you can't return from there

Because of the asynchronous nature of the communication between client and server, no return value can be sent back to the browser. https://vaadin.com/api/7.2.5/com/vaadin/ui/JavaScriptFunction.html#call(org.json.JSONArray)

To get the return value, you have to actually callback to the server (your defined showMessage method on server side) from your client side showMessage (browser/javascript). I would assume, that your main problem here is naming them both the same (I am not sure, if Vaadin applies here some package name based prefix, but most likely one of your showMessaage methods overrides the other).

You should rename your client's showMessage to something else (requestMessage below) and call your server's showMethod in there.

// client/browser/javascript (remove/rename existing showMessage from your _client_ code)
function requestMessage(m) { showMessage("Requested: "+m) }
// server/vaadin/java
Page.current.javaScript.execute("requestMessage('Hello World')")
标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!