Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.5k views
in Technique[技术] by (71.8m points)

jsf 2 - PrimeFaces' oncomplete attribute in JSF <h:commandButton>

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>?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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...
});

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...