Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

p:poll not starting immediately

Hi I am really a newbie to Jsf and Primefaces world,I have a simple query regarding primefaces poll component which is as follows.

I have a login page,once the user is authenticated i redirect him to welcome.xhtml page where i have to poll a database service every 2mins, i have used primefaces polling component for this <p:poll interval="120" listener="#{databaseService.getJob}"/> it works fine and polls after every 2mins but what i want is that once the user is authenticated and lands to welcome page the polling service should start immediately rather than waiting for the timeInterval of 2mins. To achieve this i tried using the autoStart="true"

<p:poll interval="120" listener="#{databaseService.getJob}" autoStart="true" />

but it didnt work.

So let me know how do i achieve this.

Your help is appreciated.

like image 630
user2371005 Avatar asked Feb 09 '26 21:02

user2371005


1 Answers

If you want your method to be called immediately use RemoteCommand with autoRun="true", dont use your poll component's autoStart feature and when oncomplete of RemoteCommand is triggered start your poll manually like this (untested):

<p:poll id="databaseServicePoll" interval="120" listener="#{databaseService.getJob}" autoStart="false" />

<p:remoteCommand name="firstDatabaseServiceCall" actionListener="#{databaseService.getJob}"
autoRun="true" oncomplete="databaseServicePoll.start()" />
like image 84
Ozan Tabak Avatar answered Feb 14 '26 10:02

Ozan Tabak



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!