JSF ajax event delay

主宰稳场 提交于 2019-12-23 12:42:09

问题


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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!