0

I want to make active h:selectOneMenu when h:selectBooleanCheckbox is selected.

<h:selectBooleanCheckbox value="#{user.rememberMe}" /> I agree




<h:selectOneMenu value="#{user.favCoffee1}">
    <f:selectItem itemValue="Cream Latte" itemLabel="Coffee3 - Cream Latte" />
    <f:selectItem itemValue="Extreme Mocha" itemLabel="Coffee3 - Extreme Mocha" />
    <f:selectItem itemValue="Buena Vista" itemLabel="Coffee3 - Buena Vista" />
</h:selectOneMenu>

In my cases I would like to let the user to select value from h:selectOneMenu only when he has selected that here accepts web site terms.

Peter Penzov
  • 1,126
  • 134
  • 430
  • 808

2 Answers2

2

Just bind the disabled attribute of the other component to the checkbox value and let the checkbox ajax-update the other component on change.

<h:selectBooleanCheckbox value="#{user.rememberMe}">
    <f:ajax render="menu" />
</h:selectBooleanCheckbox>

<h:selectOneMenu id="menu" ... disabled="#{not user.rememberMe}">
    ...
</h:selectOneMenu>

You only need to make sure that the managed bean holding the property bound by the disabled (and rendered and readonly) attribute is view scoped. See also How to choose the right bean scope?

In case you'd like to show/hide it via rendered attribute instead of enable/disable it via disabled attribute, then you need to wrap it in another component and ajax-update that wrapper instead. See also Why do I need to nest a component with rendered="#{some}" in another component when I want to ajax-update it?

Community
  • 1
  • 1
BalusC
  • 1,082,665
  • 372
  • 3,610
  • 3,555
0

try this:

<h:selectBooleanCheckbox value="#{user.rememberMe}" onchange="submit()"/> I agree

<h:selectOneMenu value="#{user.favCoffee1}" disabled="#{not user.rememberMe}">
            <f:selectItem itemValue="Cream Latte"
                itemLabel="Coffee3 - Cream Latte" />
            <f:selectItem itemValue="Extreme Mocha"
                itemLabel="Coffee3 - Extreme Mocha" />
            <f:selectItem itemValue="Buena Vista"
                itemLabel="Coffee3 - Buena Vista" />
        </h:selectOneMenu>
Safwan Hijazi
  • 2,089
  • 2
  • 17
  • 29