我的应用程序使用 PrimeFaces 的全局 p:ajaxStatus。每当我需要抑制/避免这种行为时,我都会在特定组件上使用 global="false",例如 p:commandButton 等。
但在这种特殊情况下,我需要像这样使用 o:socket 和 h:commandScript :
<o:socket channel="controllerEventChannel" scope="view" onmessage="onMessage" />
<h:commandScript name="onMessage" actionListener="#{backingBean.callback()}" />
我不确定是o:socket还是h:commandScript实际上触发了ajaxStatus。
如果我使用 p:remoteCommand,消息格式会破坏我使用 OmniFaces Faces.getRequestParameter(key) 的回调方法。这使我无法在 p:remoteCommand 上使用 global="false"。
关于如何手动抑制ajax状态有什么创意建议吗?
不幸的是这是不可能的。根据<p:ajaxStatus>
ajax.addOnEvent()
侦听器。
因此,最好使用
<p:remoteCommand global="false">
,并将<h:commandScript>
后面的JS函数可接受的请求参数映射参数格式转换为<p:remoteCommand>
的格式,如下所示:
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", List.of(param.getValue())))
.toList();
controllerEventChannel.send(paramsForRemoteCommand);