I want a countdown in my JSF-Page, and i solved it with <p:poll>
from Primefaces.
I have following source:
JSF-Page:
<h:form>
<h:outputText id="timeLeft" value="#{bean.secondsToGo}" />
<p:poll interval="1" listener="#{bean.countdown}" stop="#{bean.secondsToGo<0}" update="timeLeft" />
</h:form>
BEAN (view-scoped):
private int secondsToGo;
public void setValues(){ //prerenderview-event )
if(FacesContext.getCurrentInstance().isPostback()){
System.out.println("POSTBACK RECOGNIZED");
return; //ignore ajax-calls!
}
...
secondsToGo=74; //(the value depends from a GET-parameter
System.out.println("INIT: " + secondsToGo);
}
public void countdown(){
System.out.println("BEFORE: " + secondsToGo);
secondsToGo--;
System.out.println("AFTER: " + secondsToGo);
}
The funny or weird thing is that when the ajax-call is performed (p:poll), the secondsToGo is resetted to 0:
INIT: 74 //correct value
BEFORE: 0
AFTER: -1
Why?