简体   繁体   中英

RichFaces - a4j:ajax is not being triggered when using two dynamic lists

The code with the error is as follows:

<h:form>
    <rich:select defaultLabel="Seleccionar región" value="#{StaticInfo.regionElegida}">
        <f:selectItems value="#{StaticInfo.regiones.entrySet()}" var="region" itemValue="#{region.key}" itemLabel="#{region.value}" />
        <a4j:ajax event="change" render="provs" listener="#{StaticInfo.updateProvincias}" />
    </rich:select>
    <rich:select id="provs" defaultLabel="Seleccionar provincia" value="#{StaticInfo.provinciaElegida}">
        <f:selectItems value="#{StaticInfo.provincias.entrySet()}" var="prov" itemValue="#{prov.key}" itemLabel="#{prov.value}" />
        <a4j:ajax event="change" render="texto" />
    </rich:select>
    <h:outputText value="#{StaticInfo.provinciaElegida)}" id="texto" />
</h:form>

The lists display the items correctly and the bean has the required getters and setters for provinciaElegida . Now, the second select's items will depend on what is selected on the first select. And for some reason the outputText element isn't displaying any results.

Thank you.

Instead of <a4j:ajax event="change" render="texto" /> , you can try to use <a4j:support/>

<h:selectOneMenu id="selectOneMenu"  value="#{Bean1.val1}" >
    <f:selectItems value="#{Bean1.selectItems}"/>
    <a4j:support event="onchange" action="#{Bean1.onSelectOneMenuChange}" reRender="textbox1"   />
 </h:selectOneMenu>

<h:inputText id="textbox1" value="#{Bean1.textbox1}"> </h:inputText>

Just so I don't leave the question unanswered...

The problem was that the bean was Request scoped. As Luiggi explained:

When the ManagedBean is RequestScoped, it will be created for every request (even ajax requests!). If your managed bean must handle more than 1 request in the same view, it must have ViewScoped.

I was trying to submit several requests in one view, hence "resetting" the bean and effectively killing what it was supposed to do. When I changed the bean to @ViewScope, it worked perfectly.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM