为什么在这段代码中选择一个项目后,城市组件没有被渲染?
<h:form prependId="false">
<h:panelGrid columns="1">
<h:selectOneMenu value="#{enumBeanStatus.selectedRegion}">
<f:selectItems id="selectItem" value="#{enumBean.regions}" var="region" itemLabel="#{region.label}"/>
<f:ajax listener="#{enumBean.loadCities}" render="cities"/>
</h:selectOneMenu>
<h:outputText id="cities" value="#{enumBean.cities}"/>
</h:panelGrid>
</h:form>
它确实会发送带有所选区域的 POST,模型会正确更新,但<h:outputText>
不会呈现组件。
支持豆之一:
@Named
public class EnumBean {
private List<Region> regions;
private List<City> cities;
@Inject
EnumBeanStatus enumBeanStatus; //This one is CDI @ApplicationScoped & @Named
// Code...
public void loadCities(){
setCities(City.getCitiesByRegion(enumBeanStatus.getSelectedRegion()));
}
// Getters and Setters
}