考虑 JSF 页面中的以下形式:
<h:form id="countForm">
<h:outputText value="#{myBean.count}" />
<h:commandButton value="Increment the count!">
<f:ajax listener="#{myBean.increment()}" render="@form" />
</h:commandButton>
</h:form>
每当用户通过 ajax 请求单击按钮时,这个简单的代码都会增加计数器。
假设我还想在表单更新(重新呈现)时向用户显示通知计数器的新值的警报。我该怎么做?有没有类似下面的代码?
<h:form onUpdate="alert('the new value is #{myBean.count()}')">
我知道我可以使用 primefaces 的“oncomplete”方法,但事件将链接到按钮而不是表单,这不是我想要的。
计数器不是我想要做的,这只是一个简单的例子来更好地展示我的问题。
预先感谢您的任何帮助。