Reputation: 29
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.
Upvotes: 3
Views: 8315
Reputation: 672
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()" />
Upvotes: 4