从列表中的每个项目的支持 bean 方法中设置 itemDisabled
我有一个单选按钮列表,并且想根据支持 bean 方法的结果禁用某些项目。
<h:selectOneRadio value="#{managedBean.selectedItem}">
<f:selectItems value="#{managedBean.selectItems}"
var="x"
itemDisabled="#{managedBean.checkIncompatible(x)}" />
</h:selectOneRadio>
这是正确的做法吗?意思是,此代码是否会为 selectItems
列表中的每个 x
调用 checkIncomplete(x)
并将该项目设置为启用/禁用或仅一次,并且就是那个?
我只设法启用或禁用所有按钮,我怀疑该方法只被调用一次。或者我的其余代码并不像我想象的那么完美。这需要更长的时间才能解决。
I have a radiobutton list and would like to disable some items according to the outcome of a backing bean method.
<h:selectOneRadio value="#{managedBean.selectedItem}">
<f:selectItems value="#{managedBean.selectItems}"
var="x"
itemDisabled="#{managedBean.checkIncompatible(x)}" />
</h:selectOneRadio>
Is this the right way to do it? Meaning, will this code call checkIncompatible(x)
for each x
from the selectItems
list and set that item as enabled/disabled or just once and that's that?
I only managed to get all buttons to be either enabled or disabled and my suspicion is that the method only gets called once. Or that the rest of my code is not as perfect as I like to believe. And that would take a much longer question to fix.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我无法使用以下 view:
和以下 bean: 在 Mojarra 2.1.4 上重现您的问题:
上面的示例正确禁用了项目
two
。因此,您的问题是在其他地方引起的,可能是由
checkUnknown()
方法中的错误引起的。该方法上的断点告诉我,每个项目肯定都会调用它。I can't reproduce your problem on Mojarra 2.1.4 with the following view:
and the following bean:
The above example correctly disables item
two
.So, your problem is caused elsewhere, perhaps by a bug in
checkUncompatible()
method. A breakpoint on the method teaches me that it's definitely called for each item.