取消 JSF ajax 调用
我在 h:inputText
标签内有一个 f:ajax
标签,对 keyup 事件进行 ajax 调用:
<h:inputText id="searchinput" value="#{tvShowForm.name}">
<f:ajax event="keyup" render="results" listener="#{tvShowForm.search}" />
</h:inputText>
每次调用都需要足够的时间,用户在第一个调用之前已经输入了几个字符通话结束。
有没有办法取消当前的ajax调用(以及排队的ajax调用),以便最后一个keyup事件立即执行ajax调用?
I have an f:ajax
tag inside an h:inputText
tag, making ajax calls on keyup events :
<h:inputText id="searchinput" value="#{tvShowForm.name}">
<f:ajax event="keyup" render="results" listener="#{tvShowForm.search}" />
</h:inputText>
Each call takes enough time that the user has typed several characters before the first call is finished.
Is there a way to cancel the current ajax call (and the queued up ones), so that the last keyup event executes an ajax call immediately?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
听起来您想合并事件,例如这将等待
触发 ajax 请求之前半秒,以及此时键入的任何输入
点将被包括在内。但你不会为每个角色触发 ajax 请求
键入。
这是否像您想做的那样?
编辑:另一个建议是您查看 Richfaces 4 a4j:queue 功能。
这允许组合事件,例如在键盘场景中,如果您已经
靠在键盘上,当当前 ajax 请求仅完成另一次时
将发送请求。还可以指定请求延迟并忽略陈旧的请求
回应。 Richfaces 没有犯的大错误(primefaces 确实犯过)是
RF 使用与 JSF 实现相同的底层队列,因此您没有风险
无序处理。
我很感激,如果您还没有使用这个库,那么这不是一个小步骤。
It sounds like you want to coalesce the events, for example this will wait
half a second before firing an ajax request, and any input typed at that
point will be included. But you won't fire an ajax request for each character
typed.
Is this remotely like what you want to do?
EDIT: Another suggestion is that you check out the Richfaces 4 a4j:queue functionality.
This allows for combining events, for example in the keyup scenario if you've been
leaning on your keyboard, when the current ajax request completes only one further
request will be sent. It's also possible to specify a request delay and ignore stale
responses. The big mistake Richfaces doesn't make (that primefaces does make) is that
RF uses the same underlying queue as the JSF implementation, so you don't have the risk
of out-of-order processing.
I appreciate that if you're not already using this library it's not a small step to take.