在输入时提交带有 primefaces 小部件的表单 [英] Submit form with primefaces widgets on enter

查看:28
本文介绍了在输入时提交带有 primefaces 小部件的表单的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要让我的 primefaces p:commandLink 在用户按下 enter 提交一个 h:form> 键.

I need to have my primefaces p:commandLink submit a h:form when the user presses the enter key.

我尝试了此处建议的解决方案 以及其他几个地方.我还尝试了 primefaces defaultCommand.无论我尝试什么,浏览器似乎都注意到按下了按钮,但没有执行 action.

I tried the solutions suggested here and in a couple of other places. I also tried the primefaces defaultCommand. No matter what I try, the browser seems to notice the button press, but the action is not performed.

这些是我的表单的小部件:

These are my form's widgets:

<p:autoComplete id="acSimple" value="#{home.searchKeywords}" completeMethod="#{home.completeText}" style="" />
<p:commandLink id="srchbutton" action="#{home.goToSearchResults}" onclick=" $('.prgrs').show();">
    <h:graphicImage id="srch" name="images/searchbutton.jpg" class="img-responsive" style="display: inline-block; margin-left:0px; margin-bottom:-0px;"  />
</p:commandLink>
<p:defaultCommand target="srchbutton" />

推荐答案

<h:form onkeypress="if (event.keyCode == 13) { document.getElementById('form:srchbutton').click(); return false; }">

确保您的链接的真实 id 是form:srchbutton"或输入任何内容.您可以使用开发者工具或 firebug 来查找.

Make sure your real id of link is "form:srchbutton" or put whatever it is. You can use developer tools or firebug to find it out.

这篇关于在输入时提交带有 primefaces 小部件的表单的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆