【问题标题】:How to pass value into Listener in selectOneMenu如何在 selectOneMenu 中将值传递给监听器
【发布时间】:2012-10-26 00:39:30
【问题描述】:

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

【问题讨论】:

  • Ajax4jsf 是 RichFaces 的子库,带有 &lt;a4j:xxx&gt; 库的标签。你似乎没有在任何地方使用它。那么请不要在您的问题上使用[ajax4jsf] 标签。

标签: ajax jsf jsf-2


【解决方案1】:

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

【讨论】:

    【解决方案2】:

    你可以使用

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

    n 另一个选项是

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

    所以使用 a4j:support 你可以在选择类型时重新渲染代码

    【讨论】:

    • 感谢您的回复,我会检查的。也许richface4不支持a4j:支持,我看不到那个元素
    猜你喜欢
    • 2012-03-17
    • 2018-10-05
    • 2012-05-04
    • 1970-01-01
    • 2021-09-23
    • 1970-01-01
    • 2022-01-21
    • 2018-03-06
    • 1970-01-01
    相关资源
    最近更新 更多