How to pass value into Listener in selectOneMenu

ajax, jsf, jsf-2

Solution

remove the `event="valueChange"` from your `<f:ajax` or replace it with `event="change"`

You don't have to pass the value as its already there (in `changeCodeList` method)

public void changeCodeList(AjaxBehaviorEvent ev) {
    System.out.println(type); //here is your value
    //now repopulate your list based on the value
    codeList = someMethod(type);
}

Problem

I have 2 dropdowns: Type & Code. I want the Code dropdown to change values depending on the Type dropdown if value = A or B or C. How can I pass value of A or B or C into listener so it can understand and process my List ? ``` <h:outputLabel value="Type" for="idType" /> <h:selectOneMenu id="idType" value="#{myController.type}"> <f:selectItem itemLabel="AAA" itemValue="AAA" /> <f:selectItem itemLabel="BBB" itemValue="BBB" /> <f:selectItem itemLabel="CCC" itemValue="CCC" /> <f:ajax event="valueChange" listener="#{myController.changeCodeList}" render="idCode" execute="@this" /> </h:selectOneMenu> <h:outputLabel value="Code" for="idCode" /> <h:selectOneMenu id="idCode" value="#{myController.code}" > <f:selectItem itemLabel="Select ..." noSelectionOption="true" /> <f:selectItems value="#{myController.codeList}" /> </h:selectOneMenu> ```

Original source