1

I have two primefaces polls in the same page.

One of them (pollLg) has a longer interval time (30 seconds), while the other (pollSm) has a smaller interval (8 seconds).

When pollLg starts, I'd like pollSm to "pause" and then continue (remembering the time it was interrupted) after pollLg finishes its task.

If I call PF('pollSm').stop() and PF('pollSm').start() inside pollLg task, pollSm would be executed again only after 8 seconds.

For example, when the web page opens, I have:

pollSm executions: 8sec, 16sec, 24sec (pollLg will execute here and stop pollSm)

When pollLg finishes, then pollSm would execute only after 8 seconds, and not 2 seconds (it was interrupted with 6 seconds)

Is there any easy way to accomplish this?

Kukeltje
  • 12,223
  • 4
  • 24
  • 47
Bruno A
  • 117
  • 1
  • 13
  • _"Is there any easy way to accomplish this?"_ Define 'easy'... The javascript source of this component is open and can be overridden in a rather simple (or at least not too complex) way. And effectively this is not related to having two polls. Same would be for manually stopping/starting. The poll just has to 'remember' things. – Kukeltje Aug 06 '18 at 14:02
  • @Kukeltje Well, easy would be a function that already existed, like a PF('poll').pause() or something related. So, I think i'll need to modify the source code of the component? – Bruno A Aug 06 '18 at 14:10

1 Answers1

2

Let me start by stating that the PrimeFaces source is open and can be easily used for inspecting (maybe undocumented) features. I did and noticed you can't easily do this in PrimeFaces in the sense that its poll component has a built-in feature. In the javascipt source of the component you can see that it uses plain javascript timers.

So I started searching if you can do this easily in plain javascript and noticed there is no easy feature there either. Luckily there is an existing Q/A in StackOverflow about pausing/resuming a timer in javascript and it even has an answer that is about repeating timers.

If you combine this with overriding (or extending) PrimeFaces widgets, you can achieve what you want.

Kukeltje
  • 12,223
  • 4
  • 24
  • 47
  • also that being said its probably not a bad feature request for the p:poll to have the stop() method track where it stopped and add a new resume() method to the Widget if someone want to resume(). The start() method would still start the timer over. – Melloware Aug 06 '18 at 16:26
  • Thanks! I realized that I could do this without actually "pausing" the poll. But I'll definitely try to combine this with Primefaces widgets, though. – Bruno A Aug 23 '18 at 14:10