Jsf 当多个inputText和commandButton时,焦点在inputText和commandButton之间

Jsf 当多个inputText和commandButton时,焦点在inputText和commandButton之间,jsf,richfaces,Jsf,Richfaces,我正在使用richfaces和jsf 我有一张这样的表格: <h:form> <h:inputText id="id1" value="#{mybean.1}" /> <h:commandButton id="button1" action="#{otherBean.goToPage1}"> <f:ajax execute="id1" render="id1" /> </h:commandButton

我正在使用richfaces和jsf

我有一张这样的表格:

<h:form>

    <h:inputText id="id1" value="#{mybean.1}" />
    <h:commandButton id="button1" action="#{otherBean.goToPage1}">
        <f:ajax execute="id1" render="id1" />
    </h:commandButton>

    <h:inputText id="id2" value="#{mybean.2}" />
    <h:commandButton id="button2" action="#{otherBean.goToPage2}">
        <f:ajax execute="id2" render="id2" />
    </h:commandButton>        

    <h:inputText id="id3" value="#{mybean.3}" />
    <h:commandButton id="button3" action="#{otherBean.goToPage3}">
        <f:ajax execute="id3" render="id3" />
    </h:commandButton>

</h:form>

我的问题是,当我在输入“id3”上写东西并按ENTER键时,“id1”的commandButton正在读取。 或者我想要的是,当我在输入中按Enter键时,good commandButton正在读取(input1代表button1,input2代表button2,…)

对于我的项目,我只需要使用一个表单


有人有主意吗?

我找到了丢失的东西:

<h:inputText id="id1" value="#{mybean.1}" 
             onkeyup="if (event.keyCode == 13) { #{rich:element('button1')}.click();}"
             onkeydown="if (event.keyCode == 13) { #{rich:element('button1')}.click();}"/>
<h:commandButton id="button1" action="#{otherBean.goToPage1}">
    <f:ajax execute="id1" render="id1" />
</h:commandButton>


必须在每个输入文本上添加两行“onkeyup”和“onkeydown”,并替换document.getElementById('button1')

对于Internet Explorer,我添加了:onblur=“#{rich:element('button1')}。单击()”



它在IE8和IE11上工作。

您忘记关闭
“id2”
命令按钮组件。谢谢,但问题仍然存在。请停止您的问题…首先确保没有默认的命令按钮(如何执行搜索堆栈溢出)。然后在Stackoverflow中查找一个Q/a,该Q/a检测到输入中按enter键,并通过javascript“单击”右侧按钮。如果我理解正确,表单上的第一个按钮是默认按钮。我尝试加入一些javascript,但即使在研究之后,我也找不到解决问题的解决方案“如果我理解正确,表单上的第一个按钮是默认按钮。”:更正为什么keyup和keydown都可以使用?keyup可以工作,但没有keydown,我的真实代码有一些小错误。。。我不知道为什么我只是意识到这些代码在Firefox或Chrome上运行良好,但在IEI上不起作用我记得关键代码甚至事件都存在问题。但是你必须说明在其他浏览器中到底发生了什么。。。添加e.d.console.log语句我在IE控制台中没有任何内容,但它仍然不工作
<h:inputText id="id1" value="#{mybean.1}" 
             onkeyup="if (event.keyCode == 13) { #{rich:element('button1')}.click();}"
             onkeydown="if (event.keyCode == 13) { #{rich:element('button1')}.click();}"
             onblur="#{rich:element('button1')}.click();" />