How to set timeout on jsf/primefaces ajax request?

旧城冷巷雨未停 提交于 2019-12-10 19:37:11

问题


I am using JSF2/Primefaces and I was wondering how to implement a timeout callback either with jsf or primefaces ?

I want to make the timeout for the ajax request 30 seconds and if the request timed out do something as a callback .


回答1:


I put my foot where my mouth is and investigated the source and found a hint. Not to clear but a start so I did some quick Googling and one of the first hits was a PrimeFaces forum topic about setting the timeout

As a result of this (weird that I did not do that upfront), I opended the documentation and searched for timeout. Lots of hits and it in the end turned out you could do

<p:ajax timeout="30000" ... />
<p:commandButton timeout="30000" ... />

etc... So it is already built in

For acting on the 'error' there is the onerror eventhandler which takes the name of a javascript function for basic ajax handling

<p:ajax timeout="30000" onerror="doMyErrorThing" ... />
<p:commandButton timeout="30000" onerror="doMyErrorThing"... />

function doMyErrorThing(...) {
    // do your thing
}

To call a server-side method in that case call a p:remoteCommand and all should be as you want it



来源:https://stackoverflow.com/questions/52402446/how-to-set-timeout-on-jsf-primefaces-ajax-request

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