JSF selectInputDate 覆盖设置值的问题
我的 selectInputDate 有问题: 我有一个支持 bean,我将其绑定到 selectInputDate。我有一个菜单,当菜单更改时,我将现在的日期设置为 selectInputDate 绑定到的同一属性。
由于某种原因,日期更改正确,但 selectInputDate 然后调用一个集合并用旧值覆盖该值...
知道为什么 selectInputDate 会调用 setter 吗?
<ice:selectInputDate popupDateFormat="dd-MMM-yyyy" renderAsPopup="true" value="#{dateContoller.date}"/>
<ice:selectOneMenu value="#{dateContoller.dateRange}" valueChangeListener="#{dateRangeDateContoller.dateRangeChanged}" >
....
</ice:selectOneMenu>
(dateRangeChanged 将当前日期设置为现在)
I have a problem with selectInputDate:
I have a backing bean which I am binding to the selectInputDate. I have a menu which, when the menu changes, I set the date to now to the same property the selectInputDate is bound to.
For some reason, the date changes correctly, but the selectInputDate then calls a set and overrides the value with the old value...
Any idea why selectInputDate would call the setter?
<ice:selectInputDate popupDateFormat="dd-MMM-yyyy" renderAsPopup="true" value="#{dateContoller.date}"/>
<ice:selectOneMenu value="#{dateContoller.dateRange}" valueChangeListener="#{dateRangeDateContoller.dateRangeChanged}" >
....
</ice:selectOneMenu>
(dateRangeChanged sets the current date to now)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
valueChangeListener
旨在每当新提交的值与原始值不同时运行一些代码逻辑。但显然您实际上对值的更改不感兴趣,您实际上对重置提交的值感兴趣。只需摆脱
valueChangeListener
并在 bean 的操作方法中执行您的操作即可。如果由于某种原因这不是一个选项,那么您需要详细说明您认为使用
valueChangeListener
是正确解决方案的问题。无论如何,可能有一些解决方法可以保留valueChangeListener
,例如调用FacesContext#renderResponse()
,以便 JSF 不会运行更新模型值
(和调用操作
!)阶段,或者使用ValueChangeEvent#queue()
让它在调用操作
阶段重新执行自身。要了解有关 JSF 生命周期以及何时/为何/如何调用/调用一个和另一个的更多信息,您可能会发现 这篇实用文章很有用。
The
valueChangeListener
is intend to run some code logic whenever the newly submitted value differs from the original value. But you're apparently actually not interested in the change of the value, you're actually interested in resetting the submitted value.Just get rid of the
valueChangeListener
and do your thing in the bean's action method.If that is not an option for some reason, then you need to elaborate more about the problem for which you thought that using a
valueChangeListener
is the right solution. There may be workarounds to keep thevalueChangeListener
anyway, such as callingFacesContext#renderResponse()
, so that JSF won't run theupdate model values
(andinvoke action
!) phases anymore, or usingValueChangeEvent#queue()
to let it re-execute itself duringinvoke action
phase.To learn a bit more about the JSF lifecycle and when/why/how the one and other get called/invoked, you may find this practical article useful.