如何从SelectOneMenu中的选定项更新JSF SelectManyListBox项?

时间:2013-04-28 00:45:31

标签: java jsf-2

我有以下组件:

                     <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中的项目。

请帮帮我

非常感谢!

1 个答案:

答案 0 :(得分: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 );
}