JSF / Primefaces AJAX请求是否真的异步?

时间:2022-06-06 20:01:07

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

我是JSF的新手所以我不知道我面临的行为是否正常。

I have this 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>

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.

我的login.retrieveGalaxies函数有一个sleep(8000)函数来模拟延迟。我希望我的组件locationChoice1,locationChoice2和positionChoice在1或2秒内更新,我的测试组件将在8秒内更新,但所有更新都在8秒内更新。

Is this the correct behaviour?

这是正确的行为吗?

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

我尝试使用async参数,但它没有改变结果。

1 个解决方案

#1


15  

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.

它们实际上是异步的(JS上下文没有被阻止;即你可​​以在同一时刻运行其他任意JS代码而不被阻止)。你看到的行为是因为他们排队了。所以它看起来好像不是异步的。

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

这种排队行为在JSF 2规范的第13.3.2节中规定:

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.

所有Ajax请求必须在发送到服务器之前放入客户端请求队列,以确保按发送顺序处理Ajax请求。队列中等待时间最长的请求是下一个要发送的请求。发送请求后,Ajax请求回调函数必须从队列中删除请求(也称为出队)。如果请求成功完成,则必须将其从队列中删除。如果出现错误,则必须通知客户端,但仍必须从队列中删除该请求,以便可以发送下一个请求。必须发送下一个请求(队列中最早的请求)。有关Ajax请求队列的更多详细信息,请参阅jsf.ajax.request JavaScript文档。

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

这样做是为了确保JSF视图状态的完整性和线程安全性(并且因此本身也可以查看范围内的bean)。

#1


15  

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.

它们实际上是异步的(JS上下文没有被阻止;即你可​​以在同一时刻运行其他任意JS代码而不被阻止)。你看到的行为是因为他们排队了。所以它看起来好像不是异步的。

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

这种排队行为在JSF 2规范的第13.3.2节中规定:

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.

所有Ajax请求必须在发送到服务器之前放入客户端请求队列,以确保按发送顺序处理Ajax请求。队列中等待时间最长的请求是下一个要发送的请求。发送请求后,Ajax请求回调函数必须从队列中删除请求(也称为出队)。如果请求成功完成,则必须将其从队列中删除。如果出现错误,则必须通知客户端,但仍必须从队列中删除该请求,以便可以发送下一个请求。必须发送下一个请求(队列中最早的请求)。有关Ajax请求队列的更多详细信息,请参阅jsf.ajax.request JavaScript文档。

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

这样做是为了确保JSF视图状态的完整性和线程安全性(并且因此本身也可以查看范围内的bean)。