How to stop poll?

UI Components for JSF
Post Reply
jey
Posts: 3
Joined: 17 Apr 2010, 14:20

19 Apr 2010, 13:49

Hi there,

Is there a way to stop polling without clicking any buttons? The polling should start as soon I go to a page and stop when actionListener reads duration == 0

Code: Select all

private boolean stopPollingPanel1 = true;

public void checkNextDurationPanel1(ActionEvent actionEvent) {

     if (isStopPollingPanel1()) {

          duration = this value is coming from database;

          if (duration == 0) {
              stopPollingPanel1 = false; 
                    //populate database results in the RequestBean
          }
    }
}
Any help would be much appreciated!

Thank you
Jey.

G-rom
Posts: 83
Joined: 16 Mar 2010, 16:20

19 Apr 2010, 17:35

<p:poll interval="2" autoStart="true" onsuccess="poll.stop();" widgetVar="poll" />

reading dont kill http://www.primefaces.org:8080/prime-sh ... rtStop.jsf :)

jey
Posts: 3
Joined: 17 Apr 2010, 14:20

19 Apr 2010, 19:24

Thank you so much for your reply, but polling stops after first request. I want polling to continue for couple of requests.

Thanks.

G-rom
Posts: 83
Joined: 16 Mar 2010, 16:20

19 Apr 2010, 19:48

if you want it to stop after a number of request, then count them, or act on a boolean inside your bean, and evaluate it to know if you have to stop after each success.

cagatay.civici
Prime
Posts: 18616
Joined: 05 Jan 2009, 00:21
Location: Cybertron
Contact:

19 Apr 2010, 20:09

Hi, this is quite easy to implement with using poll client side api and Request callback params.

Code: Select all

public void checkNextDurationPanel1(ActionEvent actionEvent) {

     if (isStopPollingPanel1()) {

          duration = this value is coming from database;

          if (duration == 0) {
              RequestContext.getCurrentInstance().addCallbackParam("stopPoll", true);
          }
    }
}

Code: Select all

<p:poll actionListener="#{bean.checkNextDurationPanel1}" oncomplete="handlePollRequestComplete(xhr, status, args)" widgetVar="mypoll" />

Code: Select all

function handlePollRequestComplete(xhr, status, args) {
 if(args.stopPoll) {
   mypoll.stop();
 }
}
Let me know if this is not clear, basically you pass a flag from your actionlistener to the ajax oncomplete event, your javascript oncomplete event checks if you have passed this flag called stopPoll, if so poll is stopped.

danielandross
Posts: 29
Joined: 14 Feb 2011, 12:39

02 May 2011, 17:11

Hello,
I am having a problem with that solution:
The logic seem to work as my database calls will stop at the correct time.

But since I added this to my poll: ( actionListener, oncomplete, widgetVar ) the datatable I updated using attribute "update" won't refresh anymore (meaning the whole polling is useless now).
Before I added the three attributes the refresh worked properly.

Can you help me to get refresh and the poll stop working together?

The whole poll altogether looks like this:

Code: Select all

<p:poll interval="2"
				actionListener="#{bean.checkNextDurationPanel1}"
				oncomplete="handlePollRequestComplete(xhr, status, args)"
				widgetVar="mypoll" listener="#{bean.loadData}"
				update="DataTable" />
Thank you for support.

edit: The problem seems to be that I cannot use both the attribute "update" AND "oncomplete" together. But How Am I supposed to update my datatable then?

Post Reply

Return to “PrimeFaces”

  • Information
  • Who is online

    Users browsing this forum: No registered users and 51 guests