So I have an inputText that has its value hook to myBean.text, I want that if I click enter/return key, the inputText will invoke a method inside myBean to do something. Can any one help me?
As per your question history, I know that you're using JSF 2.0, so here's a JSF 2.0 targeted answer: use <f:ajax> which listens on a change event and use keypress event to invoke it when the enter key is pressed (keycode 13).
<h:inputText value="#{bean.text1}"
onkeypress="if (event.keyCode == 13) { onchange(); return false; }">
<f:ajax event="change" listener="#{bean.listener}" />
</h:inputText>
The #{bean.listener} should point to a method like
public void listener(AjaxBehaviorEvent event) {
// ...
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With