微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

ajax – 如何在selectOneMenu中将值传递给Listener

我有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>

解决方法

从< f:ajax中删除event =“valueChange”或将其替换为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);
}

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。

相关推荐