0

I have two selectManyMenu in PrimeFaces:

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

An other:

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

But I need that when an element is selected in select number one the content is loaded depending on a FK in select number two, for this I create this function:

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());
        }
    }

Using directly the List that I already have loaded, but I don't know when to execute this function? Or if there is another easier method, could you help me please?

Thanks in advance

Jasper de Vries
  • 19,370
  • 6
  • 64
  • 102

1 Answers1

1

You want to look at this example: https://www.primefaces.org/showcase-v8/ui/ajax/dropdown.xhtml

Its exactly what you want to do, change the contents of a second component based on the Selection in the first component.

Melloware
  • 10,435
  • 2
  • 32
  • 62