【问题标题】:Primefaces, Trigger command button click oncompletePrimefaces,触发命令按钮点击完成
【发布时间】:2014-05-21 11:30:26
【问题描述】:

是否可以在另一个commandButton 的oncomplete 属性上触发对commandButton 的点击?

像这样:

<p:commandButton value="save" action="#{myBean.save} oncomplete="trigger button2" />
<p:commandButton value="print" ajax="false" action="#{myBean.print}" widgetVar="button2" />

第二个按钮的属性为ajax="false"

【问题讨论】:

    标签: jsf primefaces


    【解决方案1】:

    嗯,答案就在我的问题中-.-

    <p:commandButton value="save" action="#{myBean.save}" oncomplete="$('#print').click();" />
    <p:commandButton value="print" id="print" ajax="false" action="#{myBean.print}" />
    

    保存表单,然后触发 button2 点击。

    【讨论】:

      【解决方案2】:

      您可以将p:remoteCommand 用作:

      <p:remoteCommand name="callButton2" action="#{myBean.print}" />
      

      然后在你的button-1

      <p:commandButton value="save" action="#{myBean.save} 
       oncomplete="callButton2()" />
      

      现在,如果您按保存,完成后它将调用打印方法。

      请记住,p:remoteCommand 应该包含在 form 中。

      【讨论】:

      • 我认为 p:remoteCommand 执行 ajax 调用对吗?我的第二个 commandButton 需要一个非 ajax 帖子:/(导出 pdf)
      • 你没有在你的问题中提到。尽量提供尽可能多的信息。
      • 编辑了我的问题,第二个按钮带有属性 ajax="false"
      • Thx Makky,这是一个很棒的技巧,可以在服务器端获得一个后回调函数,以便让 primefaces 完成其过程,然后只应用渲染完成。你刚刚拯救了我的一天!
      猜你喜欢
      • 2014-12-31
      • 2013-10-24
      • 1970-01-01
      • 2012-08-06
      • 2012-01-15
      • 2011-09-30
      • 1970-01-01
      • 2014-02-16
      • 1970-01-01
      相关资源
      最近更新 更多