如何在jsf/primefaces ajax请求上设置超时? [英] How to set timeout on jsf/primefaces ajax request?

查看:180
本文介绍了如何在jsf/primefaces ajax请求上设置超时?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用 JSF2/Primefaces ,我想知道如何使用jsf或primefaces实现超时回调?

我想使ajax请求的超时时间为30秒,如果请求超时,则可以做为回调.

解决方案

我将脚放在嘴里,调查了源代码,并谷歌搜索并且第一批点击之一是有关设置超时时间的 PrimeFaces论坛主题. /p>

由于这种结果(奇怪的是我没有提前这样做),我打开了

等...它已经内置了

为了处理错误",有一个onerror事件处理程序,该事件处理程序使用用于基本ajax处理的javascript函数的名称

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

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

在这种情况下,要调用服务器端方法,请调用p:remoteCommand,所有方法都应根据您的需要

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 .

解决方案

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

这篇关于如何在jsf/primefaces ajax请求上设置超时?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆