Are JSF / Primefaces AJAX really asynchronous?

I am new to JSF, so I don’t know if the behavior I encounter is normal.

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> 

The my login.retrieveGalaxies function has a sleep(8000) function call to simulate a delay. I expect my components locationChoice1 , locationChoice2 and positionChoice be updated in 1 or 2 seconds, and my test component will be updated in 8 seconds, but all will be updated in 8 seconds.

Is this the right behavior?

I tried to play with the async parameter, but it did not change the result.

+8
ajax jsf primefaces
source share
1 answer

They are really asynchronous (the JS context is not blocked, i.e. you can run other arbitrary JS code at the same time without blocking). The behavior that you see is due to the fact that they are queued. Thus, it looks as if they are not asynchronous.

This queuing behavior is specified in chapter 13.3.2 of the JSF 2 specification:

13.3.2. Ajax Request Queue

All Ajax requests must be queued for client-side requests before they are sent to ensure that Ajax requests are processed in the order in which they are sent. The request that was waiting for the longest request in the queue is the next request to send. After sending the request, the Ajax request callback function should remove the request from the queue (also called dequeuing). If the request completes successfully, it must be removed from the queue. If an error occurs, the client should be notified, but the request should still be removed from the queue, so the next request can be sent. The next request (the oldest request in the queue) should be sent. See jsf.ajax.request JavaScript for more details on the Ajax request queue.

This is to ensure the integrity and security of threads in the JSF view state (and, in fact, also view the scope of beans).

+15
source share

All Articles