Disable specific <h:selectOneRadio> items

南楼画角 提交于 2019-12-12 04:44:09

问题


I have 5 radio buttons in my form, selecting one and proceeding takes me to a form that the user need to fill up. Now out of these 5, I have not yet finished 2 of the forms that these radio buttons take me. So I wanted to disable the radio buttons which donot have the forms ready.

How I solve it now: if a user selects one of these radio buttons that donot have a form ready, it says "Page under construction" but I want to disable them completely so that no one selects it.


回答1:


If you're using f:selectItems, use the SelectItem constructor taking the disabled argument.

public class Bean {
    private List<SelectItem> selectItems;

    public Bean() {
        selectItems = new ArrayList<SelectItem>();
        selectItems.add(new SelectItem(1, "Form 1", null, false));
        selectItems.add(new SelectItem(2, "Form 2", null, false));
        selectItems.add(new SelectItem(3, "Form 3", null, false));
        selectItems.add(new SelectItem(4, "Form 4", null, true));
        selectItems.add(new SelectItem(5, "Form 5", null, true));
    }

    // getter for selectItems field ...
}

Or, if you're using f:selectItem, use the itemDisabled attribute.

<f:selectItem itemValue="1" itemLabel="Form 1" itemDisabled="false" />
<f:selectItem itemValue="2" itemLabel="Form 2" itemDisabled="false" />
<f:selectItem itemValue="3" itemLabel="Form 3" itemDisabled="false" />
<f:selectItem itemValue="4" itemLabel="Form 4" itemDisabled="true" />
<f:selectItem itemValue="5" itemLabel="Form 5" itemDisabled="true" />


来源:https://stackoverflow.com/questions/4391571/disable-specific-hselectoneradio-items

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