How to update multiple components (selectOneMenu) with dependent objects?

I have the following (self-evident) entity-relation:

* Manufacturer * Car (Manufacturer.getCars()) * Tire (Car.getTires()) 

Mybean

 private List<Manufacturer> allManufacturers private Manufacturer selectedManufacturer private Car selectedCar private Tire selectedTire 

XHTML

 <p:selectOneMenu id="manufacturerSel" value="#{myBean.selectedManufacturer}" converter="#{manufacturerConverter}"> <f:selectItem itemLabel="None" itemValue="#{null}" /> <f:selectItems value="#{myBean.allManufacturers}" /> <p:ajax update="carSel tireSel" /> </p:selectOneMenu> <p:selectOneMenu id="carSel" value="#{myBean.selectedCar}" converter="#{carsConverter}" disabled="#{empty myBean.selectedManufacturer.cars}"> <f:selectItem itemLabel="None" itemValue="#{null}" /> <f:selectItems value="#{myBean.selectedManufacturer.cars}" /> <p:ajax update="tireSel" /> </p:selectOneMenu> <p:selectOneMenu id="tireSel" value="#{myBean.selectedTire}" converter="#{tiresConverter}" disabled="#{empty myBean.selectedCar.tires}"> <f:selectItem itemLabel="None" itemValue="#{null}" /> <f:selectItems value="#{myBean.selectedCars.tires}" /> </p:selectOneMenu> 
  • last two p:selectOneMenu should be updated depending on the choice in the first
  • Last p:selectOneMenu with tireSel not updating correctly
  • All updated components are inside the same NamingContainer
  • carSel updated, but the values ​​loaded in tireSel are strange (it seems that they are valid for the last request)
  • I also tried update="@form" in manufacturerSel

EDIT To show which version of EL is being used: Here is an excerpt from my pom.xml

 <dependency> <groupId>javax.faces</groupId> <artifactId>javax.faces-api</artifactId> <version>2.1</version> </dependency> <dependency> <groupId>org.glassfish</groupId> <artifactId>javax.faces</artifactId> <version>2.1.12</version> </dependency> <dependency> <groupId>javax.el</groupId> <artifactId>el-api</artifactId> <version>2.2</version> <scope>provided</scope> </dependency> 
+6
source share
1 answer

You need to clear the selectedCar value. You can use <p:ajax listener> for this.

 <p:ajax listener="#{myBean.clearSelectedCar}" update="carSel tireSel" /> 

from

 public void clearSelectedCar() { selectedCar = null; // You might want to clear selectedTire as well. } 

Otherwise, the old selected value will still be stored in the bean, and the bus list will still depend on it.

+7
source

All Articles