4

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>
Aritz
  • 30,971
  • 16
  • 136
  • 217

2 Answers2

10

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:

Kukeltje
  • 12,223
  • 4
  • 24
  • 47
Aritz
  • 30,971
  • 16
  • 136
  • 217
0

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

Sirmyself
  • 1,464
  • 1
  • 14
  • 29
  • 1
    my bad, although, my answer is the PrimeFaces version instead of core JSF. I already faced the situation where I couldn't delay on f:ajax because we were using an older version of JSF. Primefaces have been supporting a delay for a longer time. – Sirmyself Sep 27 '17 at 17:06