0

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.

BalusC
  • 1,082,665
  • 372
  • 3,610
  • 3,555
mona
  • 6,079
  • 12
  • 41
  • 46

1 Answers1

3

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" />
Selaron
  • 6,105
  • 4
  • 31
  • 39
BalusC
  • 1,082,665
  • 372
  • 3,610
  • 3,555
  • how will I take care of it in my case? my radio buttons appear from the database. I am not sure how to utilize your suggestions – mona Dec 08 '10 at 20:08
  • 1
    As stated in my answer, use the `SelectItem` constructor which takes an extra `disabled` argument which you can set with `true` or `false`. You don't need *exactly* this code. It's just a basic example to illustrate the idea. You can always populate it dynamically, as long as you use the right constructor. – BalusC Dec 08 '10 at 20:09