problem in controlling the content of dropdown list

I want to have three dropdownlists A, B and C. The values for B depends on the value selected for A and the values for C in turn depends on the value selected for B.

I have data with parent child relationship with three levels. So at first i want only A to be visible and depending upon the value selected for A i will make B appear the value selected for A has any child. Similarly B is made visible depending upon whether or not the value selected for B has any child.

How can i implement this.

Thanks

[529 byte] By [kirandeluxea] at [2007-11-26 21:43:12]
# 1
You can use the 'rendered' attribute of the dropdownlists.
BalusCa at 2007-7-10 3:29:56 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 2

You need to point the valuechangelistener property to a method that populates your selectitems.

Your selectitems need to be bound to a property on a backing bean.

The onchange property needs to contain "submit()" so that the page is submitted and the valuechangelistener is called when a new item is selected. (Unless you use ajax, but I won't go into that here. MyFaces have some ajax selectitem components in their sandbox.)

Below is some sample jsf code:

<h:selectOneMenu id="productSelectReentry" value="#{DealForm.dynamicData['productId']}" onchange="submit()" valueChangeListener="#{QCDataForm.loadSelectItems}" rendered="#{DealForm.data.fieldMap['productId'].fieldType eq 'REENTRY'}" disabled="false" readonly="false">

<t:selectItems value="#{DealForm.data.fieldMap['productId'].selectItems}" var="Item" itemLabel="#{Item.label}" itemValue="#{Item.value}" id="productSelectItemsReentry"/>

<f:param name="path" value="fields[#{DealForm.data.fieldIndexes['productId']}].QCData"/>

</h:selectOneMenu>

Jam1ea at 2007-7-10 3:29:57 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 3

Thanks

but i found strange behavior. Actually i have added valuechangelistener for first and second dropdown list(i.e A and B), actually any change in A will invoke its valuechangelistener method, i populate the data for dropdownlist B if present depending on whether or not the selected value has any child.

I found that the valuechangelistener method of B is also invoked when dropdownlist A is changed.

I mean the change in value of dropdownlist A is also triggering the value change listener method of dropdownlist B along with valuechangelistener method of dropdown A.

kirandeluxea at 2007-7-10 3:29:57 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 4
The trigger is not due to the valueChangeListener, it is due to the onchange="submit()". It simply submits the whole form and all involved valuechangelisteners will be fired.
BalusCa at 2007-7-10 3:29:57 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 5
okso how can i prevent that behavior. I want only the valuechangelistener of that dropdownlist to be invoked which one is changed by the user not .
kirandeluxea at 2007-7-10 3:29:57 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 6
You cannot. Just check if the value is null or not. Or is not changed.It's a misunderstanding that the ValueChangeEvent will be fired automatically and autonomic when you change the value.It is just part of the whole form and intented to compare the old and new entered
BalusCa at 2007-7-10 3:29:57 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...