1
votes

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?

1
"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
@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

1 Answers

2
votes

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.