1
votes

Lets say I have two selectOneMenu drop-downs:

Drop-down A:

<h:selectOneMenu value="valA"
immediate="false"                                           
required="true"                                             
valueChangeListener="#{JavaClass.someJavaMethod}"                                           
id="caImplClassSelector"                                            
rendered="#{JavaClass.someOtherMethod}">

Drop-down B:

<h:selectOneMenu value="valB"
immediate="false"                                           
required="true"                                             
valueChangeListener="#{JavaClass.someJavaMethod}"                                           
id="caImplClassSelector"
disabled="what should I write here?"                                            
rendered="#{JavaClass.someOtherMethod}">

How can I make sure that drop down B is disabled until a user selects a value in drop down A? I can make a method within the JavaClass that returns true or false depending on if a value in drop-down A has been selected or not, but is there any way to do the above wihout making that method?

Any help would be appreciated.

2
JSF 1.x or 2.x? RichFaces 3.x or 4.x?BalusC

2 Answers

2
votes

I have no idea what JSF/RF versions you are using, so here's just a generic answer.

Bind the value of the 1st dropdown to a bean property:

<h:selectOneMenu value="#{bean.firstMenu}">

Then let the disabled attribute of the 2nd dropdown intercept on that:

<h:selectOneMenu disabled="#{bean.firstMenu == null}">

Note that with JSF2/RF4 you don't need the valueChangeListener/immediate hacks which are been used in old ajaxless JSF 1.x versions.

1
votes

Declare a boolean property in your managed bean and generate the getter and setter methods for it.

By default set it to true.

In <h:selectOneMenu value="valA" immediate="false"
required="true"
valueChangeListener="#{JavaClass.someJavaMethod}"
id="caImplClassSelector"
rendered="#{JavaClass.someOtherMethod}">

In the first drop down based on application logic on the value change listener set the disabled property to false.

In the second drop down refer to the disabled property.

There could be some additional logic that you may have to handle.