想在jsf中的Enter键上为a4j按钮提交ajax表单

时间:2022-11-24 10:33:18

I have an ajax form with a a4j:commandbutton. I want to submit the form on press of Enter key. I am using onkeypress on the commandbutton to check the enter key press. The script is called properly and after the keycode =13 check, the form doesnt get submitted. It gets submitted only if I use an alert box.

我有一个带有a4j:commandbutton的ajax表单。我想按Enter键提交表格。我在命令按钮上使用onkeypress来检查输入键按下。正确调用脚本,在keycode = 13检查后,表单不会被提交。只有在我使用警报框时才会提交。

I know as I am using ajax, it needs some delay to process, so that is done using the alert box. But if I want it to submit without the alert box?? how to do that?

我知道当我使用ajax时,它需要一些延迟来处理,所以这是使用警告框完成的。但是如果我想让它在没有警报框的情况下提交?怎么做?

Code snippet: function submitOnEnter(e) {

代码段:function submitOnEnter(e){

        var keycode;
        if (window.event) keycode = window.event.keyCode;
        else if (e) keycode = e.which;
        else return true;

    if (keycode ==13)
    {
    var form =#{rich:element('loginform:submituser')};
    alert('in alert'+form.click()); // this works and form gets submitted
            //form.click(); // i want this to work.
    return false;
    }
 else
    return true;
 }

Thanks in advance.

提前致谢。

1 个解决方案

#1


0  

You can use richfaces hotkey functionality for achieving this.What I can fathom is that you want to submit a form using Enter key. If my assumtion is right , then use following code

您可以使用richfaces热键功能来实现此功能。我可以理解您要使用Enter键提交表单。如果我的意见是正确的,那么使用以下代码

<rich:hotKey key="return"
         handler="#{rich:element('Form_Name')}.submit()" 
         selector="#Form_Name"/>

#1


0  

You can use richfaces hotkey functionality for achieving this.What I can fathom is that you want to submit a form using Enter key. If my assumtion is right , then use following code

您可以使用richfaces热键功能来实现此功能。我可以理解您要使用Enter键提交表单。如果我的意见是正确的,那么使用以下代码

<rich:hotKey key="return"
         handler="#{rich:element('Form_Name')}.submit()" 
         selector="#Form_Name"/>