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

前端 未结 1 2025
悲哀的现实
悲哀的现实 2021-01-16 14:53

This question is purely based on this previously asked question (courtesy) but the question is messed up completely with the Java EE 7 WebSockets API attempting to show the

1条回答
  •  一整个雨季
    2021-01-16 15:22

    I'm not seeing a better way than passing it as a parameter into the 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]);
        // ...
    }
    
    
    

    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).

    0 讨论(0)
提交回复
热议问题