下面是我的代码:
<h:form>
<p:autoComplete id="autoCompleteID" value="#{myBean.item}"
completeMethod="#{myBean.completeMethod}"
</p:autoComplete>
<h:commandButton action="#{myBean.searchRelatedItems}"/>
</h:form>
这里我的场景就像标准的 Google 搜索,我可以在建议中看到相关项目,还可以根据 p:autoComplete 文本字段中输入的文本重定向另一个页面。通过单击按钮可以正常工作,但我还想通过在 p:autoComplete 文本字段中按 ENTER 键来实现。
答案很晚,但我就把它留在这里......
- 尝试使用 Primefaces 命令按钮,它是 p:commandButton,而不是 h:commandButton。
- 确保commandButton的属性类型是“submit”而不是“button”,“submit”是Primefaces中的默认值。
- 最后一个(但我认为很讨厌)解决方案是在 commandButton 上放置一个 id(如“search-button”),在 h:form 上放置一个 id(如“searchForm”),然后将以下内容放在 p:autoComplete 或 h:form 上
onkeyup="if (event.keyCode === 13) { document.getElementById('searchForm:search-button').click(); return false; }"
类似主题:输入时使用 primefaces 小部件提交表单 https://stackoverflow.com/questions/30963879/submit-form-with-primefaces-widgets-on-enter
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)