PrimeFaces' oncomplete attribute in JSF <h:commandButton>

早过忘川 提交于 2019-12-29 07:56:23

问题


I didn't find an oncomplete attribute available in some tags in PrimeFaces within a standard JSF <h:commandButton>.

How can I get oncomplete-like functionality while using <h:commandButton>?


回答1:


Since primefaces oncomplete is equivalent to plain JSF success event (for more details take a look at this answer comments , you should use the success event in the following way:

Inline solution

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

Another cleaner solution would be to use js function

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

In your js file add

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

In case you are looking for a way to detect the completion of non ajax submit you can adopt the following idea from here Detecting the File Download Dialog In the Browser


The easiest solution would be to use

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


来源:https://stackoverflow.com/questions/15805825/primefaces-oncomplete-attribute-in-jsf-hcommandbutton

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!