Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can h:inputText invoke a method inside managed bean when I press the return/enter key

Tags:

jquery

jsf

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?

like image 654
Thang Pham Avatar asked Oct 14 '10 21:10

Thang Pham


Video Answer


1 Answers

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) {
    // ...
}
like image 157
BalusC Avatar answered Oct 07 '22 21:10

BalusC