【问题标题】:PrimeFaces' oncomplete attribute in JSF <h:commandButton>JSF <h:commandButton> 中 PrimeFaces 的 oncomplete 属性
【发布时间】:2013-04-04 08:13:12
【问题描述】:

我没有在标准 JSF &lt;h:commandButton&gt; 内的 PrimeFaces 的某些标签中找到 oncomplete 属性。

如何在使用&lt;h:commandButton&gt; 时获得类似oncomplete 的功能?

【问题讨论】:

  • AJAX 还是非 AJAX 请求?
  • 我很高兴知道这两种情况,但我正在寻找非 ajax
  • @Downvoter 请注意评论

标签: jsf jsf-2


【解决方案1】:

由于 primefaces oncomplete 相当于普通的 JSF success 事件(更多细节请查看 this answer comments ,您应该按以下方式使用 success 事件:

内联解决方案

<h:commandButton id="someId" action="#{myBean.myAction}">
    <f:ajax onevent="function(data) { if (data.status === 'success') { alert('complete'); }"
        render="whatevet"></f:ajax>
</h:commandButton>

另一个更干净的解决方案是使用 js 函数

<h:commandButton id="someId" action="#{myBean.myAction}">
    <f:ajax onevent="myJsFunction"
        render="whatevet"></f:ajax>
</h:commandButton>

在你的js文件中添加

function myJsFunction(data) {
    if (data.status === 'success') {
         alert('complete');
    }
}

如果您正在寻找一种方法来检测非 ajax 提交的完成情况,您可以从这里采用以下想法Detecting the File Download Dialog In the Browser


最简单的解决方案是使用

$(document).ready(function () {
// check if some condition is meet and do something...
});

【讨论】:

  • +1 是很好的解决方案,但我不会接受,因为我正在寻找非 ajax 请求。如果是非 ajax,请指导我该如何处理?
  • @despicable 如果出现非 AJAX 请求,您的页面将被重新加载,因此除了初始页面打开外,它是页面加载事件。
  • 为什么我们不在这里使用 f:ajax 的 oncomplete 功能呢?
  • @ethanjyx,f:ajax 中没有 oncomplete 属性
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2013-04-03
  • 1970-01-01
  • 2011-06-02
  • 2013-06-04
  • 2020-09-10
  • 1970-01-01
  • 2015-07-23
相关资源
最近更新 更多