Primefaces commandButton 回车时提交
我有两个命令按钮,当我按 Enter 键时,第一个按钮会提交。我真的只想在用户按回车键时提交第二个按钮。有什么想法吗?
I have two commandButtons and when I hit enter the first one submits. I really only want to submit the second button if the user hits enter. Any ideas?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我意识到这个问题已经很老了,但也许有人看到不同的解决方案仍然很有趣。
您可以使用 Primefaces defaultCommand 并将 id 添加到您喜欢的按钮来定义按下 Enter 键时会发生什么。就这样。
I realize that the question is old, but maybe it is still interessing for someone to see a different solution.
You can use the Primefaces defaultCommand and adding an id to your prefered Button to define what happens when the Enter key is pressed. That's all.
您必须交换这两个按钮的位置仅此而已。
您当前的代码应该是。
默认情况下将触发button1 操作。您可以通过向按钮 1 添加
style="float:right" 来向用户呈现另一种视图。
使用上面的方法,按钮 1 将出现在按钮 2 之后,并在每次按下 Enter 时执行按钮 2 的操作被按下。
You have to swap the position of those two buttons thats all.
Your current code should be.
By default the button1 action will be triggered. You can present the user an alternative view, by adding
style="float:right" to the button1.
Using the above the button1 will appear after the button2, and perform the action of button2, whenever the Enter is pressed.