Method being called several times in the change event of a p:ajax

Asked

Viewed 430 times

1

I have a table with a p:inputText with a p:ajax inside, the same holds the event change, when I fill that inputText with a value a query and some validations are performed. The problem is that when I glue a value within that inputText (Ctrl+v) the method is called twice. If I type the value in inputText rather than glue it the method works the right way, ie it is called only once.

xhtml:

<p:inputText id="codigoFunInput" label="Código"
   mask="9?999999999" maxlength="7" slotChar=""
   readonly="#{!item.novoFuncionario}"
   style="width:100%;text-align:" value="#{item.codigo}">
   <p:ajax event="change"
      listener="#{mbean.carregaNomeFuncionario(item)}"
      process="@this" partialSubmit="true"
      update="dataTableResponsaveis, :formTopo:topoMessage" />
</p:inputText>

What could be "spoiling" this ajax request? I have other ajax events on the screen, but they serve other things.

Note: On the screen I also have some decorates on the screen too, I do not know this can influence.

  • 1

    Probably the event attribute Event="change" is being fired on the keyboard keyUp, as Ctrl + v are two keys, so there will be 2 events (I have no small project now to test). Have you tried using the delay attribute of p:ajax ? try something like delay="1000" and see if it works.

  • I’ll try, I think I decided by changing to Blur and treating him, but if it works in the change is better

  • 1

    @wryel It worked, can answer the question :D

1 answer

3


Probably the attribute event Event="change" is being fired on the keyUp keyboard, as Ctrl + v are two keys, so there will be 2 events. Test use the delay attribute of p:ajax

<p:ajax delay="1000" event="change"  
  listener="#{mbean.carregaNomeFuncionario(item)}"
  process="@this" partialSubmit="true"
  update="dataTableResponsaveis, :formTopo:topoMessage" />

Browser other questions tagged

You are not signed in. Login or sign up in order to post.