如何在selectOneMenu中将值传递给Listener

Pet*_*ter 5 ajax jsf jsf-2

我有2个下拉菜单:类型和代码.如果值= A或B或C,我希望代码下拉列表根据类型下拉列表更改值.如何将A或B或C的值传递给侦听器,以便它可以理解和处理我的列表?

     <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>
Run Code Online (Sandbox Code Playgroud)

Dan*_*iel 7

event="valueChange"从您的删除<f:ajax或替换它event="change"

您不必将值传递给它(在changeCodeList方法中)

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