更改事件后,JSF ajax事件队列对action-event不起作用

Mis*_*ann 5 ajax jsf jsf-2 commandbutton

支持的JSF 2.x顺序处理多个ajax事件的功能对我来说不起作用.我有以下场景:

  1. h:inputText(CHANGE)

    <h:inputText id="consumption_input"
       value="#{cc.attrs.consumptionInfo.consumption}">
      <f:ajax
         render="#{cc.attrs.outerRenderString}"
         event="change" listener="#{cc.handleAjaxRequest}" />
    </h:inputText>
    
    Run Code Online (Sandbox Code Playgroud)
  2. h:commandButton(ACTION)

    <h:commandButton
        id="startComparisonButton"
        action="#{rateComparisonBean.startRateComparison()}"
        value="#{bundle.rateResultOverview_startComparison}">
        <!-- This is to avoid mixed requests, ajax and full requests -->
           <f:ajax render="@form"/>
        </h:commandButton>
    
    Run Code Online (Sandbox Code Playgroud)

如果它们自己触发,则两个元素的事件都会被正确处理.

在一次单击中触发两个事件时出现问题(在textInput中输入值,然后单击按钮).我预计这导致两个同步触发的ajax请求(CHANGE-TextField和ACTION-commandButton).

不幸的是,只有一个Ajax-Request(Change-TextField),第二个事件似乎完全丢失了.

我已经确保所有前提条件啊:commandButton都是完全填充的,如下所示: commandButton/commandLink/ajax action/listener方法未被调用或输入值未更新

我很高兴得到任何关于如何解决这个问题的提示.

环境:Glassfish 3,Mojarra 2.1.3-FCS

sku*_*sel 4

JSF AJAX 调用是异步的。发送一个 AJAX 请求(在本例中是由<h:inputText> onchange事件生成的)不会停止 JavaScipt 继续执行,并且在本例中会触发提交按钮单击,从而触发另一个 AJAX 请求。尽管如此,AJAX 请求实际上在客户端上排队,按照它们发送的确切顺序进行处理,这是JSF 2.0 规范第 13.3.2 章所保证的。

下面是我的测试用例:

风景:

<h:form id="form">
    <h:inputText id="text" value="#{q16363737Bean.text1}">
        <f:ajax render="text2" event="change" listener="#{q16363737Bean.ajaxListenerText}"/>
    </h:inputText>
    <h:commandButton id="button" action="#{q16363737Bean.actionButton}" value="Submit">
        <f:ajax render="text1 text3" listener="#{q16363737Bean.ajaxListenerButton}"/>
    </h:commandButton>
    <br/>
    <h:outputText id="text1" value="Text 1: #{q16363737Bean.text1}."/>
    <h:outputText id="text2" value="Text 2: #{q16363737Bean.text2}."/>
    <h:outputText id="text3" value="Text 3: #{q16363737Bean.text3}."/>
</h:form>
Run Code Online (Sandbox Code Playgroud)

豆子:

@ManagedBean
@ViewScoped
public class Q16363737Bean implements Serializable {

    private String text1 = "I'm text 1";//getter + setter
    private String text2 = "I'm text 2";//getter + setter
    private String text3 = "I'm text 3";//getter + setter

    public void ajaxListenerText(AjaxBehaviorEvent abe) {
        text2 = "I was modified after inputText AJAX call";
    }

    public void ajaxListenerButton(AjaxBehaviorEvent abe) {
        text1 = "I was modified after AJAX listener call of commandButton";
    }

    public void actionButton() {
        text3 = "I was modified after commandButton AJAX call";
    }

}
Run Code Online (Sandbox Code Playgroud)

在检查这个问题一段时间后,我确实发现命令按钮的 AJAX 调用很少被吞没并且没有完成 UI 更新。看来某处应该存在一些竞争条件。这是一个很大的问题,需要进一步研究。

所以,这可能不是一个答案(尽管我最初认为它是),而是一个测试用例的提议。尽管我很少遇到这种行为,但它是一个真实的用例,值得完全理解正在发生的事情。