Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

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

java - JSF2.0 - Handling erroneous Ajax calls with Primefaces 3.0

I have a commandButton in my .xhtml page:

<p:commandButton action="#{someone.doSomething()}"
                ajax="true"
                onerror="errorDialog.show();">
</p:commandButton>

It's simply making an Ajax call. How can I detect situations such as internet connection problem (of the client/browser), timeout, session-timeout, server-side exceptions, crashes etc in the middle of an Ajax call so as to show an informative message to the user?

Does the onerror attribute of p:ajax handle all of those? If not, then what? :) What's the default timeout btw?

Any help appreciated, thanks.

See Question&Answers more detail:os

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

1 Reply

0 votes
by (71.8m points)

onerror calls this function:
onerror(xhr, status, exception) - Javascript callback to process when ajax request fails. Takes three arguments, xmlhttprequest, status string and exception thrown if any.
This info is from documentation. xhr - is actually a request. So there can be found request status and a lot of other info.

<p:commandButton action="#{someone.doSomething()}"
            ajax="true"
            onerror="console.debug(xhr)">
</p:commandButton>

Try this code in chrome or firebug. It will show xhr object

Get a look into http://primefaces.googlecode.com/files/primefaces_users_guide_3_0.pdf section 7.2 Ajax API


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...