set itemDisabled from backing bean method for each item in list

雨燕双飞 提交于 2019-12-10 21:34:51

问题


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.


回答1:


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>

and the following bean:

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

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

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.



来源:https://stackoverflow.com/questions/8249625/set-itemdisabled-from-backing-bean-method-for-each-item-in-list

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!