加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

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

发布时间:2020-12-15 22:51:04 所属栏目:百科 来源:网络整理
导读:支持的JSF 2.x顺序处理多个ajax事件的功能对我来说不起作用. 我有以下场景: h:inputText(CHANGE) h:inputText id="consumption_input" value="#{cc.attrs.consumptionInfo.consumption}" f:ajax render="#{cc.attrs.outerRenderString}" event="change" li
支持的JSF 2.x顺序处理多个ajax事件的功能对我来说不起作用.
我有以下场景:

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

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

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

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

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

我已经确保h:commandButton的所有前置条件都已满,如下所示:
commandButton/commandLink/ajax action/listener method not invoked or input value not updated

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

环境:
Glassfish 3,Mojarra 2.1.3-FCS

解决方法

JSF AJAX调用是异步的.发送一个AJAX请求,在这种情况下由< h:inputText>生成onchange事件,不会阻止JavaScipt继续执行,在这种情况下,触发提交按钮单击,这反过来触发另一个AJAX请求.尽管如此,AJAX请求确实在客户端排队,按照发送的确切顺序进行处理,这由 JSF 2.0 specification第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>

豆子:

@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";
    }

}

在检查了一段时间之后,我确实发现很少有人吞下命令按钮的AJAX调用,也没有完成UI更新.似乎某处应该有一些竞争条件.这是一个很好的问题,需要进一步调查.

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

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读