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

前端 未结 6 1407
孤城傲影
孤城傲影 2021-02-03 14:54

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

6条回答
  •  無奈伤痛
    2021-02-03 15:29

    The easiest way is to put the inputText in a form and hide a commandButton next to it.

    For example:

    
      
      
    
    

    UPDATE:

    If you are using Seam you can use the tag. This makes that commandButton that contains it the one that responds to the ENTER.

    
    

    If you aren't using Seam you could try one of the similar defaultAction controls

    Or you could roll your own with a bit of Javascript; ideally jQuery. For example:

    $('input.myText').keypress(function(e) {
        if (e.which == 13) {
            $('.myButton').click();
        }
    });
    

提交回复
热议问题