使用 OmniFaces 套接字和 JSF 核心 commandScript 时如何抑制我的 PrimeFaces ajaxStatus?

问题描述 投票:0回答:1

我的应用程序使用 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状态有什么创意建议吗?

jsf primefaces omnifaces
1个回答
0
投票

不幸的是这是不可能的。根据<p:ajaxStatus>

背后JS的源代码,他们不支持根据源元素上的某个属性或特定请求参数跳过标准Faces
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);

另请参阅:

© www.soinside.com 2019 - 2024. All rights reserved.