Enter Key Press behave like Submit in JSF

前端 未结 6 1497
鱼传尺愫
鱼传尺愫 2021-01-01 07:14

How to make Enter Key Press behave like Submit in JSF. It works with InputBoxes; but not with inputSecret boxes

相关标签:
6条回答
  • 2021-01-01 07:50

    From ComputerPilot's answer I came to know that it's bug in IE which wouldn't make the parent form to submit if there's only one input element. To overcome this problem I added one more input Box with attribute style="display:none" and it worked fine.

    0 讨论(0)
  • 2021-01-01 07:52

    If you want to press ENTER key instead of submit in any form, what we have to do here is add defaultcommand attribute in af:form tag and give id of the submit button as value. Sample code snippet for this is

    <af:form id="f1" defaultCommand="cb1">
    <af:outputText value="User Name" id="usename"/>
              <af:inputText value="#{BackingBean.userName}" id="uname" />
              <af:outputText value="Password" id="pword"/>
              <af:inputText value="#{BackingBean.password}" id="paword" secret="true"/>
              <af:commandButton text="Submit" action="#{BackingBean.method}" id="cb1" />
    </af:form> 
    
    0 讨论(0)
  • 2021-01-01 07:52

    There is an old specification that pops into my mind with this one. If you have a form that contains just one input field, the behaviour of submitting on the enter-key doesn't work in some versions of Internet Explorer. The easiest fix is to make sure you have more than one input field.

    Other reasons for this problem include...

    • Not having an input of type submit
    • Having an input of type submit, but it isn't visible on the page (hidden or positioned off-page)

    This behaviour is very specific to this browser.

    MS Bug Report Here: connect.microsoft.com: submit button value not posted with form submission

    0 讨论(0)
  • 2021-01-01 07:55

    tested with jsf 2. put:

    <h:commandButton id="hidden" style="visibility: hidden;" action="#{mybean.myaction()}" />
    

    in your form

    0 讨论(0)
  • 2021-01-01 08:01

    I made it work by placing an additional inputBox and hiding it using javascript. Let me know if you have any other suggestions Thanks baluC for pointing me in the right direction Jerry

    0 讨论(0)
  • 2021-01-01 08:14

    I haven't seen this issue before. The chance is little that this behaviour is browser specific. Try in different kinds of browsers to exclude the one and other (IE6/7/8, FF, Safari, Chrome, etc). The chance is bigger that this is caused by a (poor) Javascript key event listener which incorrectly suppresses the enter key (for example a JS password validator which checks the entered characters).

    If still in vain, just add the following onkeypress to the h:form:

    <h:form onkeypress="if (event.keyCode == 13) this.submit();">
    

    You need to take textareas into account however. If you have them, then you need to copy all onkeypress events over the h:inputXXX elements expect of textareas yourself.

    0 讨论(0)
提交回复
热议问题