我在PrimeFaces中有两个selectManyMenu:
<p:selectManyMenu id="vehicleMakes"
value="#{analyticsController.selectedVehiclesMake}"
filter="true"
filterMatchMode="startsWith"
multiple="true"
scrollHeight="250"
showCheckbox="true"
styleClass="customInput manymenu-advanced"
label="#{msg['ANALYTICS-vehicle-brand-select']}">
<f:selectItems var="make" itemLabel="#{make}"
value="#{analyticsController.vehicleMakeList}"
itemValue="#{make}"
/>
<p:ajax event="change" listener="#{analyticsController.restoreFilters()}">
</p:ajax>
</p:selectManyMenu>
一个其他:
<p:selectManyMenu id="vehicleModels"
value="#{analyticsController.selectedVehiclesModel}"
filter="true"
filterMatchMode="startsWith"
multiple="true"
scrollHeight="250"
onchange="familyComponents(this, 'gfVehicleModelList', 'selectManyMenu')"
showCheckbox="true"
styleClass="customInput manymenu-advanced gfVehicleModelList"
label="#{msg['ANALYTICS-vehicle-model-select']}">
<f:selectItems
var="model"
itemLabel="#{model}"
value="#{analyticsController.vehicleModelList}"
itemValue="#{model}"
/>
</p:selectManyMenu>
但我需要的是当一个元素在select number 1中被选中时内容会根据select number 2中的FK被加载,为此我创建了这个函数:
public void filterModelBySelectedMakes(){
if (!CollectionUtils.isEmpty(selectedVehiclesMake) && !CollectionUtils.isEmpty(makes)){
List<Integer> makeIds = makes.stream().filter(make -> selectedVehiclesMake.contains(make.getName())).map(Make::getId).sorted().collect(Collectors.toList());
vehicleModelList = models.stream().filter(model -> makeIds.contains(model.getMakeId())).map(Model::getName).filter(StringUtils::isNotBlank).sorted().collect(Collectors.toList());
}
}
直接使用我已经加载的List,但我不知道何时执行这个函数?或者如果有其他更简单的方法,你能帮我吗?
Thanks in advance
您想看看这个例子:https://www.primefaces.org/showcase-v8/ui/ajax/dropdown.xhtml
这正是你想要做的,根据第一个组件的选择来改变第二个组件的内容。