简体   繁体   English

RichFaces的 - A4J:AJAX使用两个动态列表时,不被触发

[英]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 . 该名单显示正确的项目和豆为所需的getter和setter 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. 由于某种原因,outputText元素未显示任何结果。

Thank you. 谢谢。

Instead of <a4j:ajax event="change" render="texto" /> , you can try to use <a4j:support/> 取而代之的<a4j:ajax event="change" render="texto" />你可以尝试使用<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. 问题在于该bean是Request范围的。 As Luiggi explained: 正如Luiggi解释的那样:

When the ManagedBean is RequestScoped, it will be created for every request (even ajax requests!). 当ManagedBean为RequestScoped时,将为每个请求(甚至ajax请求!)也都将创建它。 If your managed bean must handle more than 1 request in the same view, it must have ViewScoped. 如果您的托管bean必须处理在同一视图超过1个请求时,它必须有ViewScoped。

I was trying to submit several requests in one view, hence "resetting" the bean and effectively killing what it was supposed to do. 我试图在一个视图中提交多个请求,从而“重置” bean并有效地杀死了它应该执行的操作。 When I changed the bean to @ViewScope, it worked perfectly. 当我将bean更改为@ViewScope时,它运行良好。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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