weixin_33696822 2015-09-28 10:57 采纳率: 0%
浏览 58

该如何跳过第二个<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());
}

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

  • 写回答

1条回答 默认 最新

  • weixin_33701564 2015-09-28 11:17
    关注

    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:

    评论

报告相同问题?

悬赏问题

  • ¥15 安卓adb backup备份应用数据失败
  • ¥15 eclipse运行项目时遇到的问题
  • ¥15 关于#c##的问题:最近需要用CAT工具Trados进行一些开发
  • ¥15 南大pa1 小游戏没有界面,并且报了如下错误,尝试过换显卡驱动,但是好像不行
  • ¥15 没有证书,nginx怎么反向代理到只能接受https的公网网站
  • ¥50 成都蓉城足球俱乐部小程序抢票
  • ¥15 yolov7训练自己的数据集
  • ¥15 esp8266与51单片机连接问题(标签-单片机|关键词-串口)(相关搜索:51单片机|单片机|测试代码)
  • ¥15 电力市场出清matlab yalmip kkt 双层优化问题
  • ¥30 ros小车路径规划实现不了,如何解决?(操作系统-ubuntu)