我有以下组件:
<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 中的项目。
请帮助我
非常感谢!
最佳答案
您将想要使用 <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 );
}
关于java - 如何从 SelectOneMenu 中的选定项目更新 JSF SelectManyListBox 项目?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16258401/