是JSF / Primefaces AJAX请求真的异步? [英] Are JSF/Primefaces AJAX requests really asynchronous?

查看:338
本文介绍了是JSF / Primefaces AJAX请求真的异步?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是新来的JSF,所以我不知道如果我现在面临的问题是正常的。

I'm new to JSF so I don't know if the behaviour I'm facing is normal.

我有这个code:

<p:selectBooleanCheckbox id="locationChoice1" value="#{login.locationChoice1}">
    <p:ajax listener="#{login.chooseLocationType1}" update="locationChoice1 locationChoice2 positionChoice" />
    <p:ajax listener="#{login.retrieveGalaxies}" update="test"  />
</p:selectBooleanCheckbox>

我的 login.retrieveGalaxies 函数调用睡眠(8000)函数来模拟延迟。我希望我的componenents locationChoice1 locationChoice2 positionChoice 是在1或2秒更新一次,我的测试组件在8 secondes进行更新,但都是在8秒更新。

My login.retrieveGalaxies function has a call to sleep(8000) function to simulate the delay. I expect my componenents locationChoice1, locationChoice2 and positionChoice to be updated in 1 or 2 seconds and my test component to be updated in 8 secondes but all are updates in 8 seconds.

这是正确的行为?

我试着用打异步参数,但它并没有改变结果。

I tried to play with async parameter but it didn't change the result.

推荐答案

他们真的异步(JS环境不堵塞;也就是说,你可以在同一时刻,而不会被运行的其他任意JS code)。你看到的行为,是因为他们在排队。因此,它的的样子的,如果他们不同步。

They're really asynchronous (JS context isn't blocked; i.e. you can run other arbitrary JS code at the same moment without being blocked). The behaviour you're seeing is because they're queued. So it look like as if they are not asynchronous.

该排队行为被指定在 JSF 2规范章13.3.2:

This queueing behaviour is specified in chapter 13.3.2 of the JSF 2 specification:

所有Ajax请求必须被放入一个客户端的请求队列,他们被送到之前   服务器,以确保Ajax请求在它们被发送的顺序进行处理。已在队列中等待的请求   最长是下一个请求被发送。后发送一个请求,Ajax请求回调函数必须删除请求   从队列(也称为出列)。如果请求成功完成后,必须将其从队列中删除。如果   有一个错误,客户端必须通知,但请求仍必须从队列,以便下一个请求删除   可以被发送。下一个请求(在队列中的最老的请求)必须发送。请参阅 jsf.ajax.request   JavaScript的文档,了解关于Ajax请求队列中更多的细节。

13.3.2 Ajax Request Queueing

All Ajax requests must be put into a client side request queue before they are sent to the server to ensure Ajax requests are processed in the order they are sent. The request that has been waiting in the queue the longest is the next request to be sent. After a request is sent, the Ajax request callback function must remove the request from the queue (also known as dequeuing). If the request completed successfully, it must be removed from the queue. If there was an error, the client must be notified, but the request must still be removed from the queue so the next request can be sent. The next request (the oldest request in the queue) must be sent. Refer to the jsf.ajax.request JavaScript documentation for more specifics about the Ajax request queue.

这是这样做保证了JSF视图状态的完整性和threadsafety(和固有因此也查看范围的Bean)。

This is done so to ensure integrity and threadsafety of the JSF view state (and inherently thus also view scoped beans).

这篇关于是JSF / Primefaces AJAX请求真的异步?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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