[英]SelectOneMenu changes its value only after the refresh
I use a SelectOneMenu
component and a SelectBooleanCheckbox
component on my JSF page. 我在JSF页面上使用了
SelectOneMenu
组件和SelectBooleanCheckbox
组件。
If the combo box is selected, my SelectOneMenu should be blocked and is set to the first element (reset). 如果选择了组合框,则应该阻止我的SelectOneMenu并将其设置为第一个元素(重置)。
Now I have value change listener for combobox implemented and blocking of the SelectOneMenu
works very well. 现在,我已经实现了组合框的值更改侦听器,并且
SelectOneMenu
阻止效果很好。
But, when I reset the ComboBox, the SelectOneMenu
is set to the old (previous) element. 但是,当我重置ComboBox时,
SelectOneMenu
被设置为旧的(上一个)元素。
I think there is something like cache used by JSF. 我认为JSF使用了类似cache的东西。
How do I reset the SelectOneMenu
control? 如何重置
SelectOneMenu
控件?
I have linked the value
-attribute to the bean property. 我已经将
value
-attribute链接到bean属性。 I set a value for this attribute in the value change listener. 我在值更改侦听器中为此属性设置了一个值。
Thanks! 谢谢!
I'll assume that you're using immediate="true"
on the checkbox and that you're calling FacesContext#renderResponse()
in your value change listener method (otherwise you would go mad with validations). 我假设您在复选框上使用了
immediate="true"
,并且在值更改侦听器方法中调用FacesContext#renderResponse()
(否则您会为验证而烦恼)。
In that case, you need to set the value of the dropdown component itself to null
as well. 在这种情况下,您还需要将下拉组件本身的值设置为
null
。
UIInput dropdown = (UIInput) facesContext.getViewRoot().findComponent("formid:dropdownid");
dropdown.setValue(null);
An alternative to UIViewroot#findComponent()
is to bind it as bean property. UIViewroot#findComponent()
的替代UIViewroot#findComponent()
是将其绑定为bean属性。
<h:selectOneMenu binding="#{bean.dropdown}">
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.