如何在selectOneMenu中将值传递给Listener

时间:2012-11-06 04:54:10

标签: ajax jsf jsf-2

我有2个下拉菜单:Type&码。如果值= 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>

2 个答案:

答案 0 :(得分:6)

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);
}

答案 1 :(得分:0)

您可以使用

<f:setPropertyActionListener value="You want to pass" target="Backing bean property that you want to set" /> 

另一种选择是

<a4j:support ajaxSingle="true" reRender="codeCombo"
                            event="onchange"></a4j:support>

所以使用a4j:支持你可以在选择类型

时重新呈现代码
相关问题