Kims
Kims

Reputation: 425

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

The update="" is being called on each interval. Is there a way to call an update only when the poll is stopped, and only once?

Eksample: How do I update button-fragment only once, when the poll stops?

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

Edit: I would like to do it from the view

Upvotes: 2

Views: 1369

Answers (1)

Smutje
Smutje

Reputation: 18173

Besides the fact that your poll never stops, I would do something similar to

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

and in the view bean

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

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

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

Edit:

Totally not tested, but perhaps this might work:

<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()
    }
}

Edit 2 (using 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()
    }
}

Upvotes: 3

Related Questions