仅当轮询在 Primefaces 中完成时,如何调用组件更新。从视图

How to call update on component, only when poll is finish in Primefaces. From the View

每个时间间隔都会调用 update=""。有没有办法只在轮询停止时调用更新,并且只调用一次?

Eksample:如何在轮询停止时仅更新一次 button-fragment

<p:poll interval="2" update="@(.button-fragment)" stop="#{stopMethod()}">

编辑:我想从视图中进行

除了你的民意调查永远不会停止之外,我会做类似的事情

<p:poll interval="2" stop="isPollStopped()" listener="updateOnPollStop()">

并在视图 bean 中

public boolean isPollStopped() {
    return ...;
}

public void updateOnPollStop() {
    final boolean pollStopped = this.isPollStopped();

    if (pollStopped) {
        RequestContext.getCurrentInstance().update("@(.button-fragment)");
    }
}

编辑:

完全没有测试,但也许这可能有效:

<p:poll interval="2" oncomplete="handlePollComplete(xhr, status, args)" stop="#{stopMethod()}">

function handlePollComplete(xhr, status, args) {
    if (!PF(<YOUR_POLL_ID>).active) {
        PF(<YOUR_UPDATEE_ID>).update()
    }
}

编辑 2(使用 remoteCommand

<p:remoteCommand name="updateOnPollStop" update="@(.button-fragment)"/>
<p:poll widgetVar="myPoll" interval="2" oncomplete="handlePollComplete(xhr, status, args)" stop="#{stopMethod()}">

function handlePollComplete(xhr, status, args) {
    if (!PF('myPoll').active) {
        updateOnPollStop()
    }
}