An integer variable is incremented each time the button is clicked and current value is updated with ajax.
Documentation<h:form> <h:panelGrid columns="2" cellpadding="5"> <h:outputText value="Counter: " /> <h:outputText id="output" value="#{counterView.number}" /> </h:panelGrid> <p:commandButton value="Count" action="#{counterView.increment}" update="output" /> </h:form>
@Named @ViewScoped public class CounterView implements Serializable { private int number; public int getNumber() { return number; } public void increment() { number++; } }