Disable specific items

2019-09-09 17: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条回答
闹够了就滚
2楼-- · 2019-09-09 17:53

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" />
查看更多
登录 后发表回答