0

我有以下组件:

                     <h:selectOneMenu id="company" 
                                 value="#{companyController.selected.companyId}" 
                                 onchange="?????????">

                    <f:selectItems value="#{companyController.itemsAvailableSelectOne}"/>
                </h:selectOneMenu>

                <h:outputLabel value="some value" for="locations" />

                <h:selectManyListbox id="locations" >
                    <f:selectItems value="#{companyController.selected.locationCollection}"/>
                </h:selectManyListbox>

每次在 SelectOneMenu 中选择一家公司时,我都需要更新 SelectManyListBox 中的项目。

请帮我

非常感谢你!

4

1 回答 1

1

您将要使用<f:ajax>. 也许是这样的:

            <h:selectOneMenu id="company" 
                             value="#{companyController.selected.companyId}">
                <f:ajax event="valueChange" execute="@this" render="@this locations" />
                <f:selectItems value="#{companyController.itemsAvailableSelectOne}"/>
            </h:selectOneMenu>

            <h:outputLabel value="some value" for="locations" />

            <h:selectManyListbox id="locations" >
                <f:selectItems value="#{companyController.selected.locationCollection}"/>
            </h:selectManyListbox>

然后你可以修改你的selected对象setCompanyId方法来更新locationCollection

public void setCompanyId( long companyId ) {
    this.companyId = companyId;
    // now update your location collection
    this.locationCollection = locationCollectionMap.get( companyId );
}
于 2013-04-28T01:20:27.923 回答