为列表中的每个项目设置从支持bean方法禁用的itemDisabled [英] set itemDisabled from backing bean method for each item in list

查看:131
本文介绍了为列表中的每个项目设置从支持bean方法禁用的itemDisabled的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个单选按钮列表,想根据后备bean方法的结果禁用某些项目.

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> 

这是正确的方法吗?含义是,此代码将为selectItems列表中的每个x调用checkIncompatible(x)并将该项目设置为启用/禁用还是仅设置一次,仅此而已?

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.

推荐答案

我无法通过以下视图在Mojarra 2.1.4上重现您的问题:

I can't reproduce your problem on Mojarra 2.1.4 with the following view:

<h:selectOneRadio value="#{bean.item}">
    <f:selectItems value="#{bean.items}" var="item" 
        itemDisabled="#{bean.isDisabled(item)}" />
</h:selectOneRadio>

和以下bean:

private String[] items = { "one", "two", "three" }; // +getter
private String item; // +getter+setter

public boolean isDisabled(String item) {
    return "two".equals(item);
}

上面的示例正确禁用了项目two.

The above example correctly disables item two.

因此,您的问题可能是由checkUncompatible()方法中的错误引起的.该方法的一个断点告诉我,绝对是每个项目都需要调用它.

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.

这篇关于为列表中的每个项目设置从支持bean方法禁用的itemDisabled的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆