简体   繁体   English

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

[英]How to update JSF SelectManyListBox items from selected item in SelectOneMenu?

I have the following components: 我具有以下组件:

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

Every time a company is selected in the SelectOneMenu i need to update the items in the SelectManyListBox. 每次在SelectOneMenu中选择一个公司时,我都需要更新SelectManyListBox中的项目。

Please Help me 请帮我

Thank you very much! 非常感谢你!

You are going to want to use <f:ajax> . 您将要使用<f:ajax> Perhaps something like this: 也许是这样的:

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

Then you could modify your selected objects setCompanyId method to update the locationCollection : 然后,您可以修改selected对象的setCompanyId方法以更新locationCollection

public void setCompanyId( long companyId ) {
    this.companyId = companyId;
    // now update your location collection
    this.locationCollection = locationCollectionMap.get( companyId );
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM