Invoking a p:remoteCommand via a JavaScript function passing a message local to that function to another function through the “oncomplete” handler

不想你离开。 提交于 2019-12-01 12:55:59
BalusC

I'm not seeing a better way than passing it as a parameter into the <p:remoteCommand> function and having the oncomplete function extract from it.

function test() {
    var message = "myMessage";
    myFunction([{name: "message", value: message}]);
}

function notifyAll(data) {
    var message = decodeURIComponent(data.match(/&message=([^&]*)/)[1]);
    // ...
}
<p:remoteCommand name="myFunction" ... oncomplete="notifyAll(this.data)" />

The data argument is already injected in the JS function scope by oncomplete and it represents the XHR query string. The regex extracts the parameter from it. Note that the regex assumes that the parameter is never in the beginning of the query string, which is true as it always starts with JSF/PF specific parameters, so it can be kept simple (JS regex is tricky with negative lookbehind).

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!