简体   繁体   中英

JSF simultaneous ajax calls

JSF是否可以进行将同时执行的ajax调用(在开始新的调用之前不等待先前的调用完成)?

No, they are explicitly queued by specification, without any exception. See chapter 13.3.2 of the JSF 2 specification :

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.

This is done so to ensure thread safety of among others the view scoped beans in the server side.

To prevent problems with the so called View-State of the page or some forms, AJAX requests are serialized.

JSF-Extensions ( https://www.intersult.com/wiki/page/JSF%20Ext ) gives you the option to parallelize AJAX requests. Just set the JavaScript variable jsf.ajaxQueue to another value than the default of 1. But if you don't lock out manually duplicate requests from within the same form or rendering of the same region, you will get errors.

This is how you activate parallel requests:

<script type="text/javascript">
    if (jsf)
        jsf.ajaxQueue = 2;
</script>

For example you can parallelize the rendering on the server of a page with <e:async>. Most applications would not need parallel requests, because they run nice when strictly serialized.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM