title: Invoking a p:remoteCommand via a JavaScript function passing a message local to that function to another function through the "oncomplete" handler
body: <p>This question is purely based on <a href="https://stackoverflow.com/q/28793083/1391249">this</a> previously asked question (<a href="https://stackoverflow.com/a/26323226/1391249">courtesy</a>) but the question is messed up completely with the Java EE 7 WebSockets API attempting to show the actual practical approach/scenario which is now very unlikely to receive any answer based on <code>&lt;p:remoteCommand&gt;</code>.</p>
  
  <hr>
  
  <p>Given below a snippet of JavaScript (this is only a test scenario).</p>
  
  <pre class="lang-javascript prettyprint-override"><code>&lt;script type="text/javascript"&gt;
      function test() {
          var message = "myMessage";
          window["myFunction"]();
          // This is literally interpreted as a JavaScript function "myFunction()".
          // "myFunction()" in turn is associated with a &lt;p:remoteCommand&gt;.
      }
  
      $(document).ready(test);
  
      function notifyAll() {
          alert("notifyAll() invoked.");
      }
  &lt;/script&gt;
  </code></pre>
  
  <p>The <code>test()</code> function is invoked as soon as the page is loaded which causes the following <a href="http://www.primefaces.org/showcase/ui/ajax/remoteCommand.xhtml" rel="nofollow noreferrer"><code>&lt;p:remoteCommand&gt;</code></a> to trigger which in turn invokes another JavaScript function, namely <code>notifyAll()</code>, using an <code>oncomplete</code> handler that simply alerts the said message.</p>
  
  <pre><code>&lt;h:form&gt;
      &lt;p:remoteCommand process="@this"
                       name="myFunction"
                       actionListener="#{bean.listener}"
                       oncomplete="notifyAll()"
                       ignoreAutoUpdate="true"/&gt;
  &lt;/h:form&gt;
  </code></pre>
  
  <p>Assume that the local JavaScript variable <code>message</code> inside the <code>test()</code> function is assigned a JSON message which is asynchronously received through a WebSockets channel.</p>
  
  <p><sub>The <code>notifyAll()</code> function in turn has to send a notification message (<code>myMessage</code> local to the <code>test()</code> function - actually a JSON message which is received previously in the <code>test()</code> function) to another WebSockets channel which is completely ignored in this question for brevity.</sub></p>
  
  <hr>
  
  <p>Is it possible to pass the value of <code>var message = "myMessage"</code> local to the <code>test()</code> function to another function <code>notifyAll()</code> through the <code>oncomplete</code> handler of the given <code>&lt;p:remoteCommand&gt;</code>?</p>
  
  <p><sub>Declaring <code>message</code> as a global JavaScript variable may overwhelm the functionality of WebSockets as the message is received <strong>asynchronously</strong> i.e. a new message may be received while the processing of <code>&lt;p:remoteCommand&gt;</code> is still going on/awaiting to complete. Thus, declaring <code>message</code> as a global JavaScript variable is not an option.</sub></p>
  
  <p>.</p>