该如何跳过第二个<p:ajax>请求?

在我的<p:commandButton>中有两个p:ajax请求,我在第二个方法中做了stdout,这样我就可以看到它是否被触发了。但是相同的方法被触发了两次,我也不知道为什么......如果我只将一个<p:ajax>请求放入我的按钮中,那么它只会触发一次,如果我放置了两个<p:ajax>请求,它会触发两次。

<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>
public void loadXMLData(){
    setXmlData(entireXmlData(mandantId(), getJobId()));
    System.out.println(getXmlData().size());
}

有人知道该如何跳过第二个负载吗?

It's because you're instructing the component to fire two ajax requests on the same (default) event. One <p:ajax> counts as one request. In other words, the code is behaving exactly as you programmed it.

You need to solve your concrete problem differently.

  1. Invoke one method which in turn delegates to the desired methods.

    <p:commandButton ... action="#{bean.methodWhichInvokesBothMethods()}" partialSubmit="true" />
    
  2. Invoke multiple methods in one call. You can use <f:actionListener binding> trick for this.

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

Either way, the <p:ajax> is totally unnecessary as the <p:commandButton> by itself already has builtin ajax support.

See also: