-
1. Re: Capturing the value of Key Presses in the Bean
bleathem Jul 5, 2013 12:34 PM (in response to blackjet)You can achieve what you are looking for by using the jsFunction component to create a javascript listener that inspects the client side event and provides the information to the backing bean via an ajax update.
"change" should be invoked when the input element loses focus.
-
2. Re: Capturing the value of Key Presses in the Bean
blackjet Jul 6, 2013 3:20 AM (in response to bleathem)Tanks very much for your reply Brian, could you provide a simple example?
EDIT: I had a look at the Showcase and dont quite understand your solution in the context of my problem :S
Many Thanks,
~Drew
-
3. Re: Capturing the value of Key Presses in the Bean
pbaker01 Jul 25, 2013 11:21 PM (in response to blackjet)Hi Drew,
Here is a simple example that checks for the tab key pressed in the last field on a toggle panel page and then moves the to first field on the next toggle panel..
<h:inputText id= "#{cid.itmUPCFld}" onkeydown="mnatSwitchTab(#{rich:component('itmTabPnl')});" value="#{inventoryController.inventoryItem.upc}" />
js code:
function mnatSwitchTab(tabComponent) { var e = event || evt; // for trans-browser compatibility var charCode = e.which || e.keyCode; if (charCode == 9) { var nextTab = tabComponent.nextItem(); if (nextTab != null) { tabComponent.switchToItem(nextTab); } else { tabComponent.switchToItem(tabComponent.firstItem()); } } }
Add js like:
<h:outputScript library="default" name="js/mnat/mnatSwitchTab.js" />
Generally, you would not want to invoke a backingbean on keyUp/keyDown type events. This would be too much chatter..
You can also call jsFunction from within js..