I would guess that when the poll triggers and updates the <selectBooleanButton>
, it sees the change and fires the valueChangeListener
, switching it back, thus the race condition. I would prefer not to mix both state and command in the same control.
My suggestion: the same code as the showcase of the component. I.e.:
<p:selectBooleanButton
id="sbbActivateTask"
value="#{taskBean.state}"
onLabel="YES"
offLabel="NO"
>
<p:ajax listener="#{taskBean.switchTask}"/>
</p:selectBooleanButton>
This way the action will only get triggered when the user actually presses the button.
In order for the button to update visually, you will need to add the update
attribute to poll
:
<p:poll
interval="5"
process="sbbActivateTask"
update="selectBooleanButton" />