我是JSF的新手,所以我不知道自己面对的行为是否正常。
我有以下代码:
<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
函数调用了sleep(8000)
函数以模拟延迟。我希望我的组件locationChoice1
,locationChoice2
和positionChoice
在1或2秒内更新,而test
组件在8秒内更新,但所有这些都在8秒内更新。这是正确的行为吗?
我尝试使用
async
参数,但没有改变结果。
最佳答案
它们实际上是异步的(未阻止JS上下文;即,您可以同时运行其他任意JS代码而不会被阻止)。您看到的行为是因为它们已排队。因此,看起来好像它们不是异步的。
此队列的行为在JSF 2 specification的第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.
这样做是为了确保JSF View 状态的完整性和线程安全性(并因此也固有地查看 View 作用域的bean)。
关于ajax - JSF/Primefaces AJAX请求真的是异步的吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13746618/