按下命令按钮时,输入文本不与后端 bean 同步
当我点击 commandButton 时,它会输入 Product.amount 开始时的值,而不是当前在输入框中键入的值。
<h:inputText value="#{product.amount}" />
<h:commandButton id="Button"
value="Buy"
tabindex="2" >
<f:ajax listener="#{shopBean.addToCart(product.product, product.amount)}"
execute="@this"
render="@all" />
</h:commandButton>
When I hit the commandButton it puts in the value that product.amount started as rather than what is currently typed in the input box.
<h:inputText value="#{product.amount}" />
<h:commandButton id="Button"
value="Buy"
tabindex="2" >
<f:ajax listener="#{shopBean.addToCart(product.product, product.amount)}"
execute="@this"
render="@all" />
</h:commandButton>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您需要将输入字段包含在
的execute
属性中,以便它也能得到处理,否则它将被完全忽略。或者只是将整个内容放在一个表单中并使用
execute="@form"
。顺便说一句,
render="@all"
违背了使用 ajax 的主要优点之一。尝试仅渲染实际需要更新的组件。You need to include the input field in the
execute
attribute of the<f:ajax>
so that it get processed as well, otherwise it will simply be ignored altogether.Or just put the whole in a single form and use
execute="@form"
.By the way, the
render="@all"
defeats one of the main advantages of using ajax. Try to render exactly only the component(s) which actually needs to be updated.