Reputation: 335
I am using PrimeFaces. And on this Keyboard, would like to use an ajax event that fires every after a key is clicked.
Here is the code:
<p:keyboard placeholder="Search" value="#{menu.searchValue}" layout="qwertyBasic">
<p:ajax event="click" listener="#{menu.search()}" update=":form:menuItems"/>
</p:keyboard>
This only works when I click in the field it's self, not when i click the keys on the keyboard.
I'm on JSF 2.2
Upvotes: 4
Views: 985
Reputation: 425
You can accomplish that with p:keyboard attributes:
For example:
<p:remoteCommand name="RC_name"
actionListener="#{TestBean.function}" />
<p:keyboard placeholder="Search"
value="#{menu.searchValue}"
layout="qwertyBasic"
onkeyup="RC_name()" >
<p:ajax event="click"
listener="#{menu.search()}"
update=":form:menuItems"/>
</p:keyboard>
Or if you want to catch specific key (for example ENTER click):
<p:keyboard value="#{menu.searchValue}"
onkeyup="if(event.keyCode == 13){
RC_name();
return false;
}" >
</p:keyboard>
Upvotes: 2