I am going through the Oracle tutorials while taking a class for Java EE and I wanted to make a dropdown menu that populates based on which radio button is selected.
To further clarify as this was marked as duplicate and it is not. I have a radio button and a dropdown menu. I want my dropdown menu to populate with data from one of four arrays in my backing bean. If the selection of the radio button changes, I want the data in the dropdown to change based on what was selected in the radio selection.
Just to be clear, this is not for an assignment.
A snippet of some of the code I have is what you see below.
This code renders the dropdown with the string array that I have in my bean for "makeHonda". It automatically renders that whether or not it is selected. I would like it to update the dropdown with car models based on which radio button is clicked.
I have looked at several different questions here and also googled as well as looking through the Oracle tutorial and I just haven't found what I am looking for. Most questions I have seen seem to have their own context and are different than what I am trying to do.
These are in my bean
private String[] carMake = {"Honda", "Nissan", "Suzuki", "Toyota"};
private String[] makeHonda = {"Civic", "NSX"};
private String[] makeNissan = {"Fairlady 420Z", "Sylvia S13"};
private String[] makeSuzuki = {"Cappuccino", "Jimny"};
private String[] makeToyota = {"Altezza RS200", "Crown"};
private String makeSelection;
private String carModels;
This stuff is in the xhtml file
<label>Favorite Car Maker: </label>
<h:selectOneRadio id="carMake" value="#{controller.makeSelection}" required="true" label="Action">
<f:selectItems value="#{controller.carMake}"/>
<f:ajax render="carModels" />
</h:selectOneRadio>
<!-- Car Models Drop Down Appears After Car Selection -->
<label>Favorite Car Model: </label>
<h:selectOneMenu id="carModels" value="#{controller.carModels}">
<f:selectItems value="#{controller.makeHonda}" rendered="#{controller.makeSelection eq 'Honda'}"/>
</h:selectOneMenu>