1

Why after selecting an item in this code, the cities component does not get rendered?

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

It does send a POST with the selected Region, model gets updated correctly, but the <h:outputText> Component is not rendered.

One of the backing beans:

@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
}
jacktrades
  • 7,224
  • 13
  • 56
  • 83
  • 1
    Note that GET after POST is not expected in this case, nor in any AJAX response, for that matter. You only want GET after POST when you are updating the full page -- and it is not automatic, you have to return "viewName.jsf?faces-redirect=true". – Elias Dorneles Jan 22 '13 at 14:20
  • @elias So, the updated information comes back in the POST Response? – jacktrades Jan 22 '13 at 14:36
  • 1
    Yes, it comes in the response for the POST request. – Elias Dorneles Jan 22 '13 at 14:57

1 Answers1

4

Remove prependId="false" from the <h:form>. It prevents <f:ajax> from resolving the right component based on a relative client ID.

See also:

Community
  • 1
  • 1
BalusC
  • 1,082,665
  • 372
  • 3,610
  • 3,555
  • EnumBean was destroyed after calling loadCities(). Made the foolish assumption that it was going to be @ApplicationScoped since it was injecting a bean of that scope. prependId did no change at all in this case. Sorry for the confusion :( – jacktrades Jan 22 '13 at 14:31