Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/jsf/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ajax 阿贾克斯发射了两次_Ajax_Jsf_Primefaces - Fatal编程技术网

Ajax 阿贾克斯发射了两次

Ajax 阿贾克斯发射了两次,ajax,jsf,primefaces,Ajax,Jsf,Primefaces,关于p:PrimeFaces的ajax。我的中有两个p:ajax请求。我在第二个方法中执行了stdout,以便查看它是否被触发。同一个(最后一个)方法被触发两次,我不知道为什么。如果我只在按钮中输入一个请求,他会触发一次,如果我输入两个请求,他会触发两次 <h:body style="background:#f5f5f5;"> <h:form id="formG"> <p:commandButton styleClass="viewButto

关于p:PrimeFaces的ajax。我的
中有两个p:ajax请求。我在第二个方法中执行了
stdout
,以便查看它是否被触发。同一个(最后一个)方法被触发两次,我不知道为什么。如果我只在按钮中输入一个
请求,他会触发一次,如果我输入两个
请求,他会触发两次

<h:body style="background:#f5f5f5;">
    <h:form id="formG">
        <p:commandButton styleClass="viewButton" icon="ui-icon-search"
            value="#{msg['button.open']}" id="auftragButtonG">

            <p:ajax listener="#{auftragBean.saveIdIntoAppScope()}"  partialSubmit="true"/>
            <p:ajax listener="#{auftragBean.loadXMLData()}" partialSubmit="true"/>
        </p:commandButton>
    </h:form>
</h:body>

有人知道我为什么以及如何忽略第二次加载吗?

这是因为您指示组件在同一(默认)事件上触发两个ajax请求。一个
计为一个请求。换句话说,代码的行为与您编程的完全相同

你需要以不同的方式解决你的具体问题

  • 调用一个方法,该方法依次委托给所需的方法

    <p:commandButton ... action="#{bean.methodWhichInvokesBothMethods()}" partialSubmit="true" />
    
    
    
  • 在一个调用中调用多个方法。您可以使用
    技巧来实现此目的

    <p:commandButton ... partialSubmit="true">
        <f:actionListener binding="#{bean.method1()}" />
        <f:actionListener binding="#{bean.method2()}" />
    </p:commandButton>
    
    
    
  • 无论哪种方式,
    都是完全不必要的,因为
    本身已经内置了ajax支持

    另见:
    <p:commandButton ... partialSubmit="true">
        <f:actionListener binding="#{bean.method1()}" />
        <f:actionListener binding="#{bean.method2()}" />
    </p:commandButton>