问题
I want to implement a live filter for a list with JSF 2 but when using keyup event so many requests are being sent to the server. The code looks like:
<h:inputText id="filter_input" value="#{bean.filterText}">
<f:ajax event="keyup" listener="#{bean.filter}"
render="@form:list" execute="@this" />
</h:inputText>
回答1:
f:ajax has added support for ajax event delay starting from JSF 2.2. Just include it as an attribute with its value in miliseconds:
<f:ajax event="keyup" delay="1000" listener="#{someBean.doSomething}"
render="somefield" execute="@this" />
See also:
- Primefaces keyup event delay
- Richfaces a4j event queuing
- Delay a JSF AJAX listener for checkbox group
- JSF 2.1 Ajax autocomplete + server search only after user stops typing
回答2:
If you are using a previous version of JSF, PrimeFaces has been supporting a similar feature before JSF did:
<p:ajax event="keyup" delay="1000" listener="#{bean.filter}"
update="somefield" process="@this" />
Note that PrimeFace does not use a render attribute nor does it use execute. Use update and process instead (although process="@this" is redundant beacuse it's already the default value for p:ajax)
here's the documentation : https://www.primefaces.org/docs/vdl/5.0/core/primefaces-p/ajax.html
And an other post that is related : primefaces keyup event delay
来源:https://stackoverflow.com/questions/32245697/jsf-ajax-event-delay