jsfprimefacesomnifaces

How do suppress my PrimeFaces ajaxStatus when using OmniFaces socket and JSF core commandScript?


My application uses PrimeFaces' global p:ajaxStatus. Whenever I need to suppress/avoid this behaviour, I use global="false" on specific components such as p:commandButton and the like.

But in this particular case, I need to use use o:socket and h:commandScript like this:

<o:socket channel="controllerEventChannel" scope="view" onmessage="onMessage" />

<h:commandScript name="onMessage" actionListener="#{backingBean.callback()}" />

I'm not sure if it's o:socket or h:commandScript that's actually triggering ajaxStatus.

If I use p:remoteCommand, the message format breaks the callback method in which I use OmniFaces Faces.getRequestParameter(key). This locks me out from using global="false" on p:remoteCommand.

Any creative suggestions on how to manually suppress the ajax status?


Solution

  • That's unfortunately not possible. According to the source code of the JS behind <p:ajaxStatus> they don't support skipping the standard Faces ajax.addOnEvent() listener based on a certain attribute on the source DOM element behind data.source or a predefined request parameter behind data.options.params.

    Your best bet is therefore to use <p:remoteCommand global="false"> and convert the request parameter map argument format acceptable by the JS function behind <h:commandScript> to the one for <p:remoteCommand> as follows:

    Map<String, Object> paramsForCommandScript = Map.of("name1", "value1", "name2", "value2");
    List<Map<String, Object>> paramsForRemoteCommand = paramsForCommandScript.entrySet().stream()
        .map(param -> Map.of("name", param.getKey(), "value", param.getValue()))
        .toList();
    controllerEventChannel.send(paramsForRemoteCommand);
    

    See also: