This content has been marked as final.
Show 2 replies
-
1. Re: How to get a4j:support for just some key press and not for all.
bkersten May 27, 2010 11:57 AM (in response to mettehummel)Hi Mette,
first of all bad news for direct usage cause AFAIK:
- u can't limit <a4j:support event="onkeyup" .../> for certain keys
- the ActionEvent object passed to your ActionListener method on server side does not contain information on the key pressed
But (if u are not afraid of some lines of JS) u could:
- use the a4j:jsFunction tag to trigger your actionListener
- trigger your own JS function for onkeyup and call the jsFunction defined above if a certain key was pressed
such as:
<a4j:jsFunction name="callMyActionListener" actionListener="myActionListener">
and
function keyUpFunction( event ){ if ( event.keyCode == Event.KEY_TAB || event.keyCode == 73 // e.g. letter "i", JS keyCodes can be found on web || event.keyCode == Event.KEY_UP ){ callMyActionListener(); } }
and the onkeyup event for the tag u wanted to use a4j:support for
<h:inputText onkeyup="keyUpFunction" />
Con: some lines of JS
Pro: compared to a server side check within the actionListener of which key was pressed this even reduces traffic and #roundtrips as an ajax request is only triggered if your desired key was pressed.
Regards
Benjamin
-
2. Re: How to get a4j:support for just some key press and not for all.
mettehummel May 28, 2010 5:04 AM (in response to bkersten)Solved my problem. Just a small addition was needed of the event as a parameter to the function.
Thanks!
<h:inputText onkeyup="keyUpFunction(event)" />