selectOneMenu 中的 hideNoSelectionOption 未按预期工作 [英] hideNoSelectionOption in selectOneMenu is not working as expected
问题描述
我有以下 selectOneMenu 并且在我的组件中我想要一个不应显示的项目,例如如果来自 #{Mybean.value} 的值与来自 #{Mybean.ListValues} 的值匹配,我不想在我的组合框中有一个空选项.
I have the following selectOneMenu and within of my component I want to have an item which shouldn't be shown, for e.g. in cases where the value from #{Mybean.value} match a value from #{Mybean.ListValues} I don't want to have an empty option in my combo box .
<p:selectOneMenu value="#{Mybean.value}" hideNoSelectionOption="true"
required="true" requiredMessage="Required data">
<f:selectItem itemLabel="" itemValue="#{null}" noSelectionOption="true" />
<f:selectItems value="#{Mybean.ListValues}" var="option" itemLabel="#{option.optionName}"
itemValue="#{option.optionId}"/>
</p:selectOneMenu>
我搜索过,但没有找到任何有用的东西,只有一个primefaces 论坛 哪里描述了这个问题.
I searched, but I didn't find anything useful, just one link in primefaces forum where describes exactly this problem.
我的 primefaces 版本是 3.5
My primefaces version is 3.5
推荐答案
从版本 9 开始支持它,请参阅其他答案.
That attribute doesn't exist in the official api or in the doc. Where did you get it from?
您实际上要寻找的是<f:selectItems
组件上的 code>itemDisabled 属性.正是此属性禁止选择 selectItem.从历史上看,primefaces 在该属性方面存在问题.
What you're actually looking for is the itemDisabled
attribute on the f:selectItems
component. It's this attribute that disables a selectItem from being selected. Historically, primefaces has had problems with that attribute.
理想情况下,你应该有
<p:selectOneMenu value="#{Mybean.value}" required="true" requiredMessage="Required data">
<f:selectItem itemLabel="" itemValue="#{null}" noSelectionOption="true" />
<f:selectItems itemDisabled="#{Mybean.value=='aValue'}" value="#{Mybean.ListValues}" var="option" itemLabel="#{option.optionName}" itemValue="#{option.optionId}"/>
</p:selectOneMenu>
这篇关于selectOneMenu 中的 hideNoSelectionOption 未按预期工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!