ajax - JSF/Primefaces AJAX请求真的是异步的吗?

标签 ajax jsf primefaces

我是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)函数以模拟延迟。我希望我的组件locationChoice1locationChoice2positionChoice在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/

相关文章:

javascript - 从 AJAX 响应中提取值

jsf - 如何将 url 参数传递给 JSF/xHTML?

jsf-2 - 下拉列表未显示在 primefaces 数据表列筛选框中

java - p :commandButton action and f:setpropertyactionlistener not invoked in p:columngroup

javascript - 在多个 const 语句中打印值

javascript - 让服务器返回然后将被调用的 JavaScript 函数的干净方法是什么?

javascript - vue-resource.common.js :1312 Uncaught ReferenceError: module is not defined(anonymous function) @ vue-resource. common.js:1312

ui :repeat 中的 JSF 文件上传

javascript - 在 JSF 中添加外部 javascript

javascript - 如何将 JSON 对象从 Java/Prime Faces 传递到 GOJS javascript 文件